我想检测用户何时停止滚动页面/元素。这可能很棘手,因为最近对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;
});
答案 0 :(得分:0)
答案 1 :(得分:0)
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);