检测滚动结束

Detect the end of overscroll

本文关键字:结束 滚动 检测      更新时间:2023-09-26

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

如何检测翻卷的结束?

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');
    }
});