Jquery检测用户交互

时间:2013-06-15 09:22:09

标签: javascript jquery html scroll jquery-animate

我有这个代码可以自动滚动页面,并在用户与页面交互时停止动画。这适用于桌面设备,但不适用于iphone。当用户尝试用手指滚动页面时,动画不会停止,直到到达页面底部。我能为此做些什么?谢谢!

$("html,body").stop().animate({scrollTop: $(document).height()}, 2000);

// Stop the animation if the user scrolls. Defaults on .stop() should be fine
$("body,html").bind("scroll mousedown DOMMouseScroll mousewheel keyup", function(e){
    $("html,body").stop();
});  

2 个答案:

答案 0 :(得分:2)

我在绑定区域添加它,它的作用是“touchstart touchmove”

$("body,html").bind("touchstart touchmove scroll mousedown DOMMouseScroll mousewheel keyup", function(e){
    $("html,body").stop();
});  

答案 1 :(得分:0)

如果只需要检测一次,则可以使用

$("body,html").one("touchstart touchmove scroll mousemove mousedown DOMMouseScroll mousewheel keyup", function(e){
    console.log('Detected');
});
相关问题