-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
49 lines (44 loc) · 1.29 KB
/
main.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
const slides = document.querySelectorAll(".slide");
const next =document.querySelector("#next");
const prev = document.querySelector("#prev");
let auto = true;
let slideInterval;
function nextSlide(){
const current = document.querySelector(".current");
current.classList.remove("current");
if(current.nextElementSibling){
current.nextElementSibling.classList.add("current")
}else {
slides[0].classList.add("current");
}
// i dont get this part
setTimeout(current.classList.remove("current"))
}
function prevSlide(){
const current = document.querySelector(".current");
current.classList.remove("current");
if(current.previousElementSibling){
current.previousElementSibling.classList.add("current")
}else {
slides[slides.length - 1].classList.add("current");
}
// i dont get this part
// setTimeout(current.classList.remove("current"))
}
next.addEventListener("click", () => {
nextSlide();
if(auto){
clearInterval(slideInterval);
slideInterval = setInterval(nextSlide,4000)
}
})
prev.addEventListener("click", () => {
prevSlide();
if(auto){
clearInterval(slideInterval);
slideInterval = setInterval(nextSlide,4000)
}
})
if(auto){
slideInterval = setInterval(nextSlide,4000)
}