-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
53 lines (45 loc) · 1.92 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
(function () {
var kitties = document.querySelectorAll(".kitty-container img");
const interval = 5000;
var currentKitty = 0;
var dots = document.getElementsByClassName("dot");
for (var index=0; index<dots.length; index++) {
dots[index].setAttribute("data-index",index);
dots[index].addEventListener("click",function(e) {
clearTimeout(timer);
kitties[currentKitty].classList.add("offscreen-left");
kitties[currentKitty].classList.remove("onscreen");
timer = setTimeout(moveKitties,7000);
for (var innerLoop=0; innerLoop<dots.length; innerLoop++) {
if (dots[innerLoop]==e.target) {
currentKitty=innerLoop;
dots[innerLoop].classList.add("on");
kitties[innerLoop].classList.add("onscreen");
} else {
dots[innerLoop].classList.remove("on");
}
}
});
}
function moveKitties() {
kitties[currentKitty].classList.remove("onscreen");
kitties[currentKitty].classList.add("offscreen-left");
dots[currentKitty].classList.remove("on");
currentKitty++;
if (currentKitty >= kitties.length) {
currentKitty = 0;
}
kitties[currentKitty].classList.add("onscreen");
kitties[currentKitty].classList.remove("offscreen-left");
dots[currentKitty].classList.add("on");
timer = setTimeout(moveKitties, interval);
}
var timer = setTimeout(moveKitties, interval);
document.addEventListener("transitionend", function () {
for (var counter = 0; counter<kitties.length; counter++) {
if (kitties[counter].classList.contains("offscreen-left")) {
kitties[counter].classList.remove("offscreen-left");
}
}
});
})();