-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction2.js
More file actions
45 lines (36 loc) · 1.17 KB
/
Copy pathfunction2.js
File metadata and controls
45 lines (36 loc) · 1.17 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
43
44
45
document.addEventListener("DOMContentLoaded", () => {
let slideIndex = 1;
showSlides(slideIndex);
// Go to next or previous slide
window.plusSlides = function(n) {
showSlides(slideIndex += n);
};
// Go to a specific slide
window.currentSlide = function(n) {
showSlides(slideIndex = n);
};
function showSlides(n) {
const slides = document.getElementsByClassName("mySlides");
const dots = document.getElementsByClassName("dot");
// if no slides exist, stop
if (!slides.length) {
console.error("No slides found with class 'mySlides'");
return;
}
// Loop back if out of range
if (n > slides.length) slideIndex = 1;
if (n < 1) slideIndex = slides.length;
// Hide all slides
for (let i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
// Remove 'active' class from all dots
for (let i = 0; i < dots.length; i++) {
dots[i].classList.remove("active");
}
// Show the correct slide
slides[slideIndex - 1].style.display = "block";
// Highlight the correct dot (if it exists)
if (dots[slideIndex - 1]) dots[slideIndex - 1].classList.add("active");
}
});