Skip to content
Advertisement

infinite scroll doesn’t stop when contents finish

hi am having a problem with infinite scroll functionality, when all the contents have been displayed it still continues to scroll (strange behavior). i am looking for a way to stop the infinite scroll when all contents are displayed

here is my code

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

i have bee working on this days now….please heeeeeeeeeeelllllllllpppppp 🙁

Advertisement

Answer

You can try unbinding it from window object. Suppose your last page reached then use this function

$(window).unbind('scroll');
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement