问题
There's been similar questions on how to fire scroll events (mid-scroll) on mobile/tablet. I've used the code provided below but I've yet to get this to work in chrome emulator.
$('body').on({
'touchmove': function(e) {
console.log($(this).scrollTop()); // Replace this with your code.
}
});
touchstart will log when I scroll with the touch sensor but not touchmove. What am I missing?
回答1:
Did you enable the "emulate touch screen"?
check this link in "sensors" http://www.sitepoint.com/use-mobile-emulation-mode-chrome/
Try this code
<script type="text/javascript">
$(document).bind('touchmove', function(e) {
console.log($(this).scrollTop());
});
</script>
回答2:
I use bind
and originalEvent
, which works on real mobile device:
$("html").bind("touchmove", function(e)
{
e.preventDefault();
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
var x = touch.pageX, y =touch.pageY;
来源:https://stackoverflow.com/questions/29302188/jquery-touchmove-not-registering-in-chrome-emulator