infinite-scroll jquery plugin

rajh2504 picture rajh2504 · Feb 20, 2011 · Viewed 50.1k times · Source

I am trying to set up infinite-scroll on a site I am developing with Coldfusion, I am new to javascript and jquery so I am having some issues wrapping my head around all of this. Do I need to have pagination on my site in order to use the infinite-scroll plugin, or is there a way to do it with out it?

Answer

Hussein picture Hussein · Feb 20, 2011

You do not need infinite scroll plug-in for this. To detect when scroll reaches end of page, with jQuery you can do

$(window).scroll(function () { 
   if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
      //Add something at the end of the page
   }
});

Demo on JsFiddle