如何在jQuery Endless Scroll插件中停止TOP Scroll Load

时间:2016-08-24 22:53:46

标签: javascript jquery html infinite-loop endlessscroll

我正在尝试为我的网站创建无限循环。我正在使用 jQuery Endless Scroll插件

<script type='text/javascript' src='/js/jquery.min.js'></script>
<script type='text/javascript' src='/js/jquery.endless-scroll.js'></script>

$(document).ready(function() {
    $(window).endlessScroll({
        inflowPixels: 300,
                ceaseFireOnEmpty :false,
        callback: function() {
            var $img = $('#clmn-a .box:nth-child(4)').clone();
            $('#clmn-a').append($img);
        }
    });
});

一切正常,但此功能也在顶部滚动上运行。我想仅在用户到达页脚附近时才加载数据。那么如何在 jQuery Endless Scroll插件中禁用Top Scroll Load

PluginLink:https://github.com/fredwu/jquery-endless-scroll

1 个答案:

答案 0 :(得分:0)

试试这个:

$(document).ready(function() {

    EndlessScroll.prototype.detectScrollDirection = function() {
        var currentScrollTop;
        this.didScroll = true;
        currentScrollTop = $(this.target).scrollTop();
        if (currentScrollTop > this.lastScrollTop) {
          this.scrollDirection = 'next';
        }
        else{
        }
        return this.lastScrollTop = currentScrollTop;
      };


    $(window).endlessScroll({
        inflowPixels: 300,
                ceaseFireOnEmpty :false,
        callback: function() {
            var $img = $('#clmn-a .box:nth-child(4)').clone();
            $('#clmn-a').append($img);
        }
    });
});