jQuery touchmove not registering in chrome emulator

你离开我真会死。 提交于 2019-12-25 02:52:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!