1
我想检测手机上的滚动/触摸方向。对于桌面,我使用.on('DOMMouseScroll')
和.('mousewheel')
,但这在手机上不起作用。 页的正文是overflow: hidden;
任何人都知道如何检测此?溢出时的移动滚动方向检测:隐藏页面
我想检测手机上的滚动/触摸方向。对于桌面,我使用.on('DOMMouseScroll')
和.('mousewheel')
,但这在手机上不起作用。 页的正文是overflow: hidden;
任何人都知道如何检测此?溢出时的移动滚动方向检测:隐藏页面
看来我陷入了你的情况。
因为我需要大量的研究,把所有东西放在一起,我在这里张贴了一切:
if (Modernizr.touch) {
// Determining swipe direction
// http://stackoverflow.com/a/22257774/1064325
var touchStartY;
document.addEventListener('touchstart', function (e){
touchStartY = e.touches[0].clientY;
}, false);
// Preventing iOS end of page bounce effect
// http://stackoverflow.com/a/7771215/1064325
document.addEventListener('touchmove', function (e){
e.preventDefault();
}, false);
document.addEventListener('touchend', function (e){
var touchEndY = e.changedTouches[0].clientY;
if (touchStartY > touchEndY + 5) {
// NEXT
} else if (touchStartY < touchEndY - 5) {
// PREV
}
}, false);
} else {
// Handling wheeling properly
// http://stackoverflow.com/a/3515490/1064325
var deltaWheel = 0;
var wheelTimeout = 0;
document.addEventListener('wheel', function(event) {
deltaWheel += event.deltaY;
clearTimeout(wheelTimeout);
wheelTimeout = setTimeout(function() {
if (deltaWheel < -5) {
// PREV
}
if (deltaWheel > +5) {
// NEXT
}
deltaWheel = 0;
}, 50);
});
}
是否使用JQM?它有'scrollstart'和'scrollstop'的一些虚拟事件。 https://api.jquerymobile.com/category/events/ – Twisty