Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Last active June 29, 2016 23:20
Show Gist options
  • Save pamelafox/a8b77c43f56da1753348 to your computer and use it in GitHub Desktop.
Save pamelafox/a8b77c43f56da1753348 to your computer and use it in GitHub Desktop.
slideshow.js
/**
* This function takes in a reference to a DOM element,
* assumes each of its children are <img> tags,
* and then makes a simple slideshow out of the images.
* @param container A DOM element
*/
var slideShow = function(container) {
this.images = [];
this.curImage = 0;
for (i = 0; i < container.childElementCount; i++) {
this.images.push(container.children[i]);
this.images[i].style.display = "none";
}
// Handle going to to the next slide
var nextSlide = function() {
for (var i = 0; i < this.images.length; i++) {
this.images[i].style.display = "none";
}
this.images[this.curImage].style.display = "block";
this.curImage++;
if (this.curImage >= this.images.length) {
this.curImage = 0;
}
window.setTimeout(nextSlide.bind(this), 500);
};
nextSlide.call(this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment