Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.