内容完成后无限滚动不会停止

问题描述 投票:0回答:2

他在无限滚动功能方面遇到问题,当所有内容都显示完后,它仍会继续滚动(奇怪的行为)。我正在寻找一种在显示所有内容时停止无限滚动的方法

这是我的代码

<script type="text/javascript">
jQuery(document).ready(function ($) {
(function () {
   var page = 1,
   loading = false,
   finish = false;


function nearBottomOfPage() {
return $(window).scrollTop() > $(document).height() - $(window).height() - 200;
 }

 function finish() {
  finish = true;

}
 $(window).scroll(function () {
  if (loading) {
   return;
 }
if (nearBottomOfPage() && !finish) {
  loading = true;
  $('#loader').show();
  page++;
  $.ajax({
    url: '/office?page=' + page,
    type: 'get',
    dataType: 'script',
    success: function () {
      $('#loader').hide();
      loading = false;
    }
  });
  }
});
}());

我现在正在这方面工作。...请heeeeeeeeeeeeelllllllllpppppppp :(

javascript jquery ruby-on-rails-3.2 infinite-scroll
2个回答
1
投票

您可以尝试将其与窗口对象解除绑定。假设您到达的最后一页,然后使用此功能

$(window).unbind('scroll');

0
投票

Hello Folks,我刚遇到同样的问题!经过数小时的在线搜索并尝试了许多解决方案,我提出了这个解决方案。

infinite-scroll.js文件中搜索该变量:

t.children()

然后将其值从(1 == 1)更改为(0 == 1),如下所示:

case"append":var l=t.children();if(1==l.length)return this._error("end");

收件人:

case"append":var l=t.children();if(0==l.length)return this._error("end");

现在,当您到达帖子末尾时,应该显示FinishedMsg

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.