Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created March 31, 2010 08:24
Show Gist options
  • Save jakearchibald/350087 to your computer and use it in GitHub Desktop.
Save jakearchibald/350087 to your computer and use it in GitHub Desktop.
Simple image slideshow
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