【问题标题】:infinite scroll doesn't stop when contents finish内容完成后无限滚动不会停止
【发布时间】:2012-09-08 12:11:57
【问题描述】:

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

这是我的代码

<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;
    }
  });
  }
});
}());

我这几天一直在工作....请 heeeeeeeeeeellllllllllpppppp :(

【问题讨论】:

  • 你不是在你的脚本中调用完成()。从您的后端添加一个属性以指示何时没有页面:)
  • hmmmm 我想知道如何指定何时没有页面......任何建议。
  • 那么,你是怎么做分页的?

标签: javascript jquery ruby-on-rails-3.2 infinite-scroll


【解决方案1】:

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

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

【讨论】:

  • 我在哪里放置这个 $(window).unbind('scroll');...是在 nearBottomOfPage 函数之后还是在其中...请给我一个例子...谢谢
  • 是的,你必须把它放在最后一页检查条件之后
  • hmmm 但我的代码似乎没有最后一页的条件...你能帮帮我吗
【解决方案2】:

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

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

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-22
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多