Created
March 31, 2010 08:24
-
-
Save jakearchibald/350087 to your computer and use it in GitHub Desktop.
Simple image slideshow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var images = glow.dom.get('#imagesToCycle img'), | |
| currentImage = 0; | |
| images.css({ // give all the images a z-index of 1 | |
| position: 'absolute', | |
| 'z-index': '1' | |
| }).slice(0, 1).css('z-index', '2'); // give the image we want to be on top a z-index of 2 | |
| function showNextImage() { | |
| currentImage++; | |
| // if we're past the last image, loop round to the start | |
| if (currentImage === images.length) { | |
| currentImage = 0; | |
| } | |
| var imageToShow = images.slice(currentImage, currentImage+1); | |
| // move the image we want to show to the top | |
| imageToShow.css({ | |
| 'z-index': '3', | |
| 'opacity': '0' | |
| }); | |
| // fade the image in | |
| glow.anim.fadeIn(imageToShow, 1, { | |
| // when the animate completes | |
| onComplete: function() { | |
| // move all images to the bottom of the stack | |
| images.css('z-index', '1'); | |
| // except the one we just displayed | |
| imageToShow.css('z-index', '2') | |
| } | |
| }); | |
| } | |
| // run showNextImage every 5 seconds | |
| setInterval(showNextImage, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment