Alternatives to jQuery endless scrolling

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

    This should do the same trick without plugin

    $(window).scroll(function () { 
       if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
          //Add something at the end of the page
       }
    });
    

    EDIT Jan 15, 2014

    According to @pere's comment, it's better to use the code below to avoid excessive amount of event firing.

    Inspired from this answer https://stackoverflow.com/a/13298018/153723

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

提交回复
热议问题