Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Forked from ryanb/index.js.erb
Created December 16, 2011 23:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seyhunak/1488549 to your computer and use it in GitHub Desktop.
Save seyhunak/1488549 to your computer and use it in GitHub Desktop.
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
jQuery ->
if $('.pagination').length
$(window).scroll ->
url = $('.pagination .next_page').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
$('.pagination').text("Fetching more products...")
$.getScript(url)
$(window).scroll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment