-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
30 lines (25 loc) · 798 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
29
30
// A javascript file for handling a photo slideshow
let activeIndex = 0;
let previousIndex = 0;
showSlides(activeIndex);
// A function to increment the current active slide by n indexes
function plusSlides(n) {
previousIndex = activeIndex;
activeIndex += n;
showSlides(activeIndex);
}
function showSlides(n) {
// Retrieve all elements with the 'slide' class
let slides = document.getElementsByClassName("slide");
// Handle index overflow
if (n >= slides.length) {
activeIndex = 0;
}
else if (n < 0) {
activeIndex = slides.length - 1;
}
// Set the previous slide's display to none
slides[previousIndex].style.display = "none";
// Set the current slide's display to block
slides[activeIndex].style.display = "block";
}