-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslideshow.js
71 lines (65 loc) · 1.56 KB
/
slideshow.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
63
64
65
66
67
68
69
70
71
var slideIndex = 0;
var slides;
var dots;
var timer;
var slideShowDelay = 5000;
function plusDivs(n) {
slideIndex += n;
slideIndex %= slides.length;
if (slideIndex == -1) {
slideIndex += slides.length;
}
slides[slideIndex].className =
slides[slideIndex].className.replace(" w3-animate-left", "");
slides[slideIndex].className =
slides[slideIndex].className.replace(" w3-animate-right", "");
if (n > 0) {
slides[slideIndex].className += " w3-animate-right";
} else if (n < 0) {
slides[slideIndex].className += " w3-animate-left";
}
showDivs(slideIndex);
}
function currentDiv(n) {
if (slideIndex == n) {
plusDivs(0);
} else if (n < slideIndex) {
while (n < slideIndex) {
plusDivs(-1);
}
} else if (n > slideIndex) {
while (n > slideIndex) {
plusDivs(1);
}
}
}
function initImages() {
slides = document.getElementsByClassName("mySlides");
dots = document.getElementsByClassName("demo");
for (i = 1; i < slides.length; i++) {
slides[i].style.display = "none";
}
currentDiv(0);
}
function showDivs(n) {
var i;
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" w3-white", "");
}
slides[slideIndex].style.display = "block";
dots[slideIndex].className += " w3-white";
restartTimer();
}
function carousel() {
plusDivs(1);
restartTimer();
}
function restartTimer() {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(carousel, slideShowDelay)
}