Detecting scroll finish/end

核能气质少年 提交于 2019-12-23 10:15:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!