Skip to content

Instantly share code, notes, and snippets.

@javiertoledo
Created February 13, 2012 23:13
Show Gist options
  • Save javiertoledo/1821351 to your computer and use it in GitHub Desktop.
Save javiertoledo/1821351 to your computer and use it in GitHub Desktop.
A simple multi-instance slideshow with jQuery
.photos
- @photos.each do |photo|
.photo=image_tag photo.url(:medium)
updateSlideshows = ->
for slideshow in $('.photos')
if (active = $('.active',slideshow)).length == 0
if activable = $('.photo',slideshow)[0]
$(activable).addClass('active')
$(activable).fadeIn(500)
else if (activable = (active.next('.photo')[0] || $('.photo',slideshow)[0]))
$(activable).addClass('active')
$(activable).fadeIn(1000)
$(active).removeClass('active')
$(active).fadeOut(1000)
$ ->
window.setInterval(updateSlideshows,6000)
updateSlideshows()
.photos
width: 640px //The images width here
height: 480px //The images height here
position: relative
.photo
display: none //Initially hiddes all slides
position: absolute
top: 0
left: 0
.active
z-index: 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment