Alternatives to jQuery endless scrolling

前端 未结 5 1428
粉色の甜心
粉色の甜心 2021-01-30 04:26

Are there any alternatives to the jQuery endless scrolling plugin?

http://www.beyondcoding.com/2009/01/15/release-jquery-plugin-endless-scroll/

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 05:22

    This should take care of a bug where the user reaches the bottom of the page before the event fires. I was seeing this in my project you should check prior to initializing the event if you're already at the bottom of the page.

    var scrollListener = function () {
        executeScrollIfinBounds();
        $(window).one("scroll", function () { //unbinds itself every time it fires
           executeScrollIfinBounds();
            setTimeout(scrollListener, 200); //rebinds itself after 200ms
        });
    };
    $(document).ready(function () {
        scrollListener();
    });
    
    function executeScrollIfinBounds()
    {
         if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
                //Add something at the end of the page
            }
    }
    

提交回复
热议问题