Skip to content

Instantly share code, notes, and snippets.

@jeangontijo
Last active June 14, 2018 14:40
Show Gist options
  • Save jeangontijo/b19b6ca373276944ea49726b7c4c1dd7 to your computer and use it in GitHub Desktop.
Save jeangontijo/b19b6ca373276944ea49726b7c4c1dd7 to your computer and use it in GitHub Desktop.
setInterval Change Class
var slider = document.getElementById("hero");
var classes = ['slide1', 'slide2', 'slide3', 'slide4'];
var myInterval = setInterval(function () {
changeClass()
}, 5000);
var i = 0;
function changeClass() {
slider.classList = classes[i];
i < classes.length - 1 ? i++ : i = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment