-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpeople.js
39 lines (34 loc) · 972 Bytes
/
people.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
/*
* Dynamic gallery using querySelector
* Thanks to Stack Overflow for guidance regarding the dynamic slider
*/
//Events variables
let slides = document.querySelector('.slider-items').children;
let nextSlide = document.querySelector(".right-slide");
let prevSlide = document.querySelector(".left-slide");
let totalSlides = slides.length;
let index = 0;
nextSlide.onclick = function() { // Move to the next slide
next("next");
};
prevSlide.onclick = function() { // Move to the previous slide
next("prev");
};
function next(direction) {
if (direction == "next") { // if/else statement
index++;
if (index == totalSlides) {
index = 0;
}
} else {
if (index == 0) {
index = totalSlides - 1;
} else {
index--;
}
}
for (i = 0; i < slides.length; i++) { // For loop
slides[i].classList.remove("active");
}
slides[index].classList.add("active");
}