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

时间:2012-09-15 17:31:44

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

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

这是我的代码

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

我现在正忙着工作....请heeeeeeeeeeelllllllllpppppp :(

2 个答案:

答案 0 :(得分:1)

您可以尝试从窗口对象中取消绑定它。 假设您的最后一页已到达,请使用此功能

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

答案 1 :(得分:0)

你好乡亲, 我只是遇到了同样的问题!经过数小时的在线搜索并尝试了许多解决方案,我提出了这个解决方案。

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F0F5F6" tools:context=".MainActivity"> <EditText android:id="@+id/totalNumber" android:layout_width="211dp" android:layout_height="0dp" android:layout_marginBottom="60dp" android:autofillHints="" android:ems="10" android:hint="@string/total_numbers_in_the_lotto" android:inputType="number" app:layout_constraintBottom_toTopOf="@+id/btnPrint" app:layout_constraintEnd_toEndOf="@+id/btnPrint" app:layout_constraintStart_toStartOf="@+id/btnPrint" app:layout_constraintTop_toBottomOf="@+id/EndNumber" /> <EditText android:id="@+id/EndNumber" android:layout_width="211dp" android:layout_height="0dp" android:layout_marginBottom="40dp" android:autofillHints="" android:ems="10" android:hint="End Number" android:inputType="number" app:layout_constraintBottom_toTopOf="@+id/totalNumber" app:layout_constraintEnd_toEndOf="@+id/totalNumber" app:layout_constraintStart_toStartOf="@+id/totalNumber" app:layout_constraintTop_toBottomOf="@+id/StartNumber" /> <EditText android:id="@+id/StartNumber" android:layout_width="211dp" android:layout_height="0dp" android:layout_marginBottom="40dp" android:autofillHints="" android:ems="10" android:hint="Start Number" android:inputType="number" app:layout_constraintBottom_toTopOf="@+id/EndNumber" app:layout_constraintEnd_toEndOf="@+id/EndNumber" app:layout_constraintStart_toStartOf="@+id/EndNumber" app:layout_constraintTop_toBottomOf="@+id/editText" /> <EditText android:id="@+id/editText" android:layout_width="211dp" android:layout_height="0dp" android:layout_marginTop="60dp" android:layout_marginBottom="40dp" android:ems="10" android:hint="Enter Your Name" android:inputType="textPersonName" app:layout_constraintBottom_toTopOf="@+id/StartNumber" app:layout_constraintEnd_toEndOf="@+id/StartNumber" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="@+id/StartNumber" app:layout_constraintTop_toTopOf="parent" /> <Button android:id="@+id/btnPrint" android:layout_width="183dp" android:layout_height="0dp" android:layout_marginBottom="100dp" android:text="Print Your Lucky Numbers" app:layout_constraintBottom_toTopOf="@+id/resultLotto" app:layout_constraintEnd_toEndOf="@+id/resultLotto" app:layout_constraintStart_toStartOf="@+id/resultLotto" app:layout_constraintTop_toBottomOf="@+id/totalNumber" /> <TextView android:id="@+id/resultLotto" android:layout_width="262dp" android:layout_height="0dp" android:layout_marginBottom="150dp" android:text="Result" android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textColor="#F44336" android:textSize="36sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/btnPrint" /> </androidx.constraintlayout.widget.ConstraintLayout> 文件中搜索该变量:

infinite-scroll.js

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

t.children()

收件人:

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

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

希望这会有所帮助。