Restarting Infinite Ajax Scroll after jQuery.load ()

I am working on a site where I want to implement infinite scrolling. I found the IAS plugin and it works fine except for one instance. If I load new content into a div using the jQuery.load () function, infinite scrolling stops working.

<script type="text/javascript">

  $(document).ready(function() {

    var ias = $.ias({
      container:    '#load_here',
      item:       'p',
      pagination: '#nav',
      next:       '#nav a'
    });

    $("#reload").click(function(){
      event.preventDefault();

      $("#test").load( "page0.html #load_here", function() {

        // Reinitialize the infinite scrolling here.

      });
    });
  });

</script>

Here is the documentation for the IAS plugin: http://infiniteajaxscroll.com/docs/overview.html

I found the following questions that seem relevant, but it seems to me that I do not have clear answers - I am sorry that they are not links, Stack Overflow will not allow me to send more than two links:

  • stackoverflow.com/questions/24419462/

  • stackoverflow.com/questions/25205507/

  • stackoverflow.com/questions/20404493/

  • github.com/webcreate/infinite-ajax-scroll/issues/68

destroy, , , , . , , , .

1, 2 3 . , 0 jQuery.load(), . 1, 2 3.

.

0
1

100% , , - , $("#test").load(... , ias, .

, :

$("#test").load( "page0.html #load_here", function() {

  // Reinitialize the infinite scrolling here.
  var ias = $.ias({
    container:  '#load_here',
    item:       'p',
    pagination: '#nav',
    next:       '#nav a'
  });

});

, $.ias() memoizing , "ias" .

, ias , , . "destroy" $.ias() , . (https://github.com/webcreate/infinite-ajax-scroll/blob/master/src/jquery-ias.js#L553)

, , :

var ias;

function setupIAS() {
  ias && $.ias('destroy');
  ias = $.ias({
    container:    '#load_here',
    item:       'p',
    pagination: '#nav',
    next:       '#nav a'
  });
}

$(document).ready(function() {

  setupIAS();

  $("#reload").click(function(){
    event.preventDefault();

    $("#test").load( "page0.html #load_here", function() {

      // Reinitialize the infinite scrolling here.
      setupIAS();

    });
  });
});
+1

All Articles