I'm using Kaminari for pagination. And here is the code which i'm using for infinite scroll:
jQuery(function() {
if ($('.pagination').length) {
$(window).scroll(function() {
var url;
url = $('.pagination .next_page').attr('href');
if(url && $(window).scrollTop()>$(document).height()-$(window).height()-50)
{
$('.pagination').text("Fetching more products...");
return $.getScript(url);
}
});
return $(window).scroll();
}
The above code I've written in a document.ready function. And then this code is written in .js.erb file
$("#container1").append("<%= escape_javascript(render 'shirts/first')%>");
<% if @first.next_page %>
$('.pagination').replaceWith("<%= j paginate @first %>");
<% else %>
$('.pagination').remove();
<% end %>
<% sleep 1 %>
});
But I'm not getting the infinite scroll. Can someone guide me as where I'm going wrong?