-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
37 lines (34 loc) · 1.11 KB
/
main.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
const nextBtn = document.querySelector(".next-btn");
const prevBtn = document.querySelector(".prev-btn");
const slides = document.querySelectorAll(".box");
const slideIcons = document.querySelectorAll(".slide-icon");
const numberSlides = slides.length;
var slideNumber = 0;
nextBtn.addEventListener("click", () => {
slideNumber++;
slides.forEach((box) => {
box.classList.remove("active");
});
slideIcons.forEach((slideIcon) => {
slideIcon.classList.remove("active");
});
if(slideNumber > (numberSlides - 1)){
slideNumber = 0;
}
slides[slideNumber].classList.add("active");
slideIcons[slideNumber].classList.add("active");
});
prevBtn.addEventListener("click", () => {
slides.forEach((box) => {
box.classList.remove("active");
});
slideIcons.forEach((slideIcon) => {
slideIcon.classList.remove("active");
});
slideNumber--;
if(slideNumber < 0){
slideNumber = numberSlides - 1;
}
slides[slideNumber].classList.add("active");
slideIcons[slideNumber].classList.add("active");
});