Skip to content

Instantly share code, notes, and snippets.

@todoubled
Created November 23, 2011 22:30
Show Gist options
  • Select an option

  • Save todoubled/1390120 to your computer and use it in GitHub Desktop.

Select an option

Save todoubled/1390120 to your computer and use it in GitHub Desktop.
Infinitely scroll through an array of items in any direction.
# Shuffle items front and back to flow infinitely
infiniteFlow: () =>
last = $("#{@config.id} section.item:last-child")
first = $("#{@config.id} section.item:first-child")
outer = $('.items')
if last.hasClass('right') or last.hasClass('current')
oldLeft = outer.position().left
width = first.width()
newLeft = oldLeft + width
outer.append first
outer.css 'left', newLeft
if first.hasClass('left') or first.hasClass('current')
oldLeft = outer.position().left
width = last.width()
newLeft = oldLeft - width
outer.prepend last
outer.css 'left', newLeft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment