检测过度滚动的结束

时间:2014-12-06 19:06:34

标签: javascript ios

当元素的webkit-overflow-scrolling设置为"触摸" (默认为iOS设备上的document.documentElement),然后用户可以过度滚动内容。当用户释放touchevent时,元素滚动到0需要一些时间。

如何检测过度滚动的结束?

1 个答案:

答案 0 :(得分:1)

var overscroll;

window.addEventListener('touchstart', function () {
    // User has very quick fingers.
    overscroll = false;
});

window.addEventListener('touchend', function () {
    // User released touch-drag event when element was in an overscroll state.
    if (document.body.scrollTop < 0) {
        overscroll = true;
    }
});

window.addEventListener('scroll', function () {
    if (overscroll && document.body.scrollTop == 0) {
        overscroll = false;

        console.log('end of overscroll');
    }
});