-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (44 loc) · 1.52 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
let nextDom = document.getElementById("next");
let prevDom = document.getElementById("prev");
let carouselDom = document.querySelector(".carousel");
let sliderDom = carouselDom.querySelector(".carousel .list");
let thumbnailBorderDom = document.querySelector(".carousel .thumbnail");
let thumbnailItemsDom = thumbnailBorderDom.querySelectorAll(".item");
let timeDom = document.querySelector(".carousel .time");
thumbnailBorderDom.appendChild(thumbnailItemsDom[0]);
let timeRunning = 3000;
let timeAutoNext = 7000;
nextDom.onclick = function () {
showSlider("next");
};
prevDom.onclick = function () {
showSlider("prev");
};
let runTimeOut;
let runNextAuto = setTimeout(() => {
next.click();
}, timeAutoNext);
function showSlider(type) {
let SliderItemsDom = sliderDom.querySelectorAll(".carousel .list .item");
let thumbnailItemsDom = document.querySelectorAll(
".carousel .thumbnail .item"
);
if (type === "next") {
sliderDom.appendChild(SliderItemsDom[0]);
thumbnailBorderDom.appendChild(thumbnailItemsDom[0]);
carouselDom.classList.add("next");
} else {
sliderDom.prepend(SliderItemsDom[SliderItemsDom.length - 1]);
thumbnailBorderDom.prepend(thumbnailItemsDom[thumbnailItemsDom.length - 1]);
carouselDom.classList.add("prev");
}
clearTimeout(runTimeOut);
runTimeOut = setTimeout(() => {
carouselDom.classList.remove("next");
carouselDom.classList.remove("prev");
}, timeRunning);
clearTimeout(runNextAuto);
runNextAuto = setTimeout(() => {
next.click();
}, timeAutoNext);
}