-
-
Save logan4dog/e357a6c30b4f0ce51a972551b2439d55 to your computer and use it in GitHub Desktop.
slideshow.js
This file contains 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
/** | |
* 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