Scroll event firing too many times. I only want it to fire a maximum of, say, once per second

后端 未结 8 729
再見小時候
再見小時候 2020-11-27 12:24

I have a page with \"infinite scroll\". It calculates the difference between the end of the page and the current page and loads more content if this difference is small enou

8条回答
  •  春和景丽
    2020-11-27 12:56

    There is a cool explanation from John Resig, the creator of jQuery to resolve this situation.

    var outerPane = $details.find(".details-pane-outer"),
        didScroll = false;
    
    $(window).scroll(function() {
        didScroll = true;
    });
    
    setInterval(function() {
        if ( didScroll ) {
            didScroll = false;
            // Check your page position and then
            // Load in more results
        }
    }, 250);
    

    The source: http://ejohn.org/blog/learning-from-twitter/

提交回复
热议问题