Skip to content

Instantly share code, notes, and snippets.

@chestone
Created January 21, 2011 04:16
Show Gist options
  • Save chestone/789237 to your computer and use it in GitHub Desktop.
Save chestone/789237 to your computer and use it in GitHub Desktop.
A div with an id of 'slideshow' contains five images, the first of which is shown and the others are hidden using a display style of none. Using Javascript, create a simple slideshow that cycles through the images, displaying each image for three seconds
var imgs = document.getElementById('slideshow').getElementsByTagName('img');
var currIdx = 0;
setInterval(function() {
imgs[currIdx].style.display = 'none';
currIdx = (currIdx + 1 == imgs.length) ? 0 : currIdx + 1;
imgs[currIdx].style.display = '';
}, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment