Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RailsScript Infinite Scroll
window.App ||= {}
class App.GemgentoCategories extends App.Base
show: =>
new App.ProductGrid()
# Enable infinite scrolling
infiniteScroll: ->
navSelector: "div.pagination"
nextSelector: "div.pagination a:first"
itemSelector: "#category-products div.tile"
bufferPx: 1200
, (arrayOfNewElem) ->
# hide the pagination link if we didn't load a full page
if arrayOfNewElem.length != 12
$(window).trigger('resize') # make sure the tiles are all sized correctly
# hide images and fade in once loaded
$(arrayOfNewElem).each ->
$imageWrapper = $('.image-wrapper', this)
$('img', $imageWrapper).hide()
$imageWrapper.imagesLoaded ->
$('img', $imageWrapper).fadeIn()
# pause the infinite scroll when user navigates away
$(document).on 'page:fetch', ->
# resume infinite scroll when page is restored
$(document).on 'page:restore', ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.