-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (47 loc) · 1.21 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const testimonials = document.querySelectorAll('.testimonial');
const images = document.querySelectorAll('.photo');
const arrowPrev = document.querySelector('#arrowPrev');
const arrowNext = document.querySelector('#arrowNext');
let currentActive = 0, length;
if (testimonials.length == images.length) {
totalLength = images.length;
}
function reset() {
for (let i = 0; i < totalLength; i++) {
testimonials[i].style.opacity = '0';
images[i].style.opacity = '0';
}
}
// slider initializer
function init() {
reset();
testimonials[0].style.opacity = '1';
images[0].style.opacity = '1';
}
// show previous
function goPrev() {
reset();
testimonials[currentActive - 1].style.opacity = '1';
images[currentActive - 1].style.opacity = '1';
currentActive--;
}
arrowPrev.addEventListener('click', function () {
if (currentActive === 0) {
currentActive = totalLength;
}
goPrev();
});
// show next
function goNext() {
reset();
testimonials[currentActive + 1].style.opacity = '1';
images[currentActive + 1].style.opacity = '1';
currentActive++;
}
arrowNext.addEventListener('click', function () {
if (currentActive === totalLength - 1) {
currentActive = -1;
}
goNext();
});
init();