-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (32 loc) · 869 Bytes
/
index.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
29
30
31
32
33
34
35
36
37
38
39
// IMAGE SLIDER
const slides = document.querySelectorAll(".slides img");
let slideIndex = 0;
let intervalId = null;
document.addEventListener("DOMContentLoaded", initializeSlider);
function initializeSlider(){
if(slides.length > 0){
slides[slideIndex].classList.add("displaySlide");
intervalId = setInterval(nextSlide, 5000);
}
}
function showSlide(index){
if(index >= slides.length){
slideIndex = 0;
}
else if(index < 0){
slideIndex = slides.length - 1;
}
slides.forEach(slide => {
slide.classList.remove("displaySlide");
});
slides[slideIndex].classList.add("displaySlide");
}
function prevSlide(){
clearInterval(intervalId);
slideIndex--;
showSlide(slideIndex);
}
function nextSlide(){
slideIndex++;
showSlide(slideIndex);
}