问题
I'd like to detect when a user has stopped scrolling a page/element. This may be tricky as recently enhancements to OSX's scrolling behaviour creates this new inertia effect. Is there an event fired?
The only other solution I can think of is using a interval to pick up when the scroll position of a page/element no longer changes, for example:
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;
});
回答1:
Take a look at this, its jquery, and working well for me, hope to work for you.
Also there is an other scroll event code in here.
回答2:
This may be useful.
// 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);
来源:https://stackoverflow.com/questions/10817088/detecting-scroll-finish-end