-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (33 loc) · 1 KB
/
Copy pathscript.js
File metadata and controls
42 lines (33 loc) · 1 KB
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
40
41
42
document.addEventListener("DOMContentLoaded", () => {
const dots = document.querySelectorAll(".dots-wrapper ul li");
const images = document.querySelectorAll(".images-wrapper img");
let currentIndex = 0;
let intervalId;
const setActiveSlide = (index) => {
dots.forEach((d) => d.classList.remove("active"));
images.forEach((img) => img.classList.remove("active"));
dots[index].classList.add("active");
images[index].classList.add("active");
currentIndex = index;
};
setActiveSlide(0);
const nextSlide = () => {
currentIndex = (currentIndex + 1) % images.length;
setActiveSlide(currentIndex);
};
const startAutoPlay = () => {
intervalId = setInterval(nextSlide, 2500);
};
const stopAutoPlay = () => {
clearInterval(intervalId);
};
dots.forEach((dot) => {
dot.addEventListener("click", () => {
stopAutoPlay();
const index = parseInt(dot.dataset.index);
setActiveSlide(index);
startAutoPlay();
});
});
startAutoPlay();
});