Created
March 4, 2022 14:02
-
-
Save mpdroog/06f67da05c2c08ff88d5d41297ef3a23 to your computer and use it in GitHub Desktop.
Minimal JS to implement bootstrap carousel
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
var global = { | |
carousels: [], | |
slide: 0, | |
}; | |
function nextSlide() { | |
console.log("nextSlide", global); | |
global.carousels[global.slide].classList.toggle("active"); | |
global.slide++; | |
if (global.slide > global.carousels.length - 1) { | |
global.slide = 0; | |
} | |
global.carousels[global.slide].classList.toggle("active"); | |
} | |
global.carousels = document.getElementsByClassName("carousel-item"); | |
if (global.carousels.length > 0) { | |
window.setInterval(nextSlide, 3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment