-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (19 loc) · 908 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var slideshows = document.querySelectorAll('[data-component="slideshow"]');
// Apply to all slideshows that you define with the markup wrote
slideshows.forEach(initSlideShow);
function initSlideShow(slideshow) {
var slides = document.querySelectorAll(`#${slideshow.id} [role="list"] .slide`); // Get an array of slides
var index = 0, time = 5000;
slides[index].classList.add('active');
slides[index].style.visibility = "visible";
setInterval( () => {
slides[index].classList.remove('active');
slides[index].style.visibility = "hidden";
//Go over each slide incrementing the index
index++;
// If you go over all slides, restart the index to show the first slide and start again
if (index === slides.length) index = 0;
slides[index].classList.add('active');
slides[index].style.visibility = "visible";
}, time);
}