gpt4 book ai didi

javascript - 检测滚动完成/结束

转载 作者:搜寻专家 更新时间:2023-11-01 04:42:34 26 4
gpt4 key购买 nike

我想检测用户何时停止滚动页面/元素。这可能很棘手,因为最近对 OSX 滚动行为的增强创造了这种新的惯性效应。是否触发了事件?

我能想到的唯一其他解决方案是在页面/元素的滚动位置不再改变时使用间隔来拾取,例如:

var element     = $( el );
var previous = element.scrollLeft();
var current;

element.scroll( function(event)
{
current = element.scrollLeft();

if ( current === previous )
{
// user has stopped scrolling
}

previous = current;
});

最佳答案

This可能有用。

// Setup isScrolling variable
var isScrolling;

// Listen for scroll events
window.addEventListener('scroll', function ( event ) {

// Clear our timeout throughout the scroll
window.clearTimeout( isScrolling );

// Set a timeout to run after scrolling ends
isScrolling = setTimeout(function() {

// Run the callback
console.log( 'Scrolling has stopped.' );

}, 66);

}, false);

关于javascript - 检测滚动完成/结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10817088/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com