Alternatives to jQuery endless scrolling

前端 未结 5 1427
粉色の甜心
粉色の甜心 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:18

    Combining Ergec's answer and Pere's comment:

    function watchScrollPosition(callback, distance, interval) {
        var $window = $(window),
            $document = $(document);
    
        var checkScrollPosition = function() {
            var top = $document.height() - $window.height() - distance;
    
            if ($window.scrollTop() >= top) {
                callback();
            }
        };
    
        setInterval(checkScrollPosition, interval);
    }
    

    distance is the number of pixels from the bottom of the screen when the callback will fire.

    interval is how often the check will run (in milliseconds; 250-1000 is reasonable).

提交回复
热议问题