-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (46 loc) · 1.25 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
const progress = document.getElementById('progress')
const prev = document.getElementById('prev')
const next = document.getElementById('next')
const circles = document.querySelectorAll('.circle')
let currentSlide = 1
next.addEventListener('click',()=>{
currentSlide++;
if(currentSlide > circles.length){
currentSlide=circles.length;
}
// console.log(currentSlide)
update()
})
prev.addEventListener('click',()=>{
currentSlide--;
if(currentSlide < 1){
currentSlide=1;
}
// console.log(currentSlide)
update()
})
function update(){
circles.forEach((circle,idx)=>{
if(currentSlide > idx){
circle.classList.add('active')
}
else{
circle.classList.remove('active')
}
})
const actives = document.querySelectorAll('.active')
actives.forEach((active)=>{
// console.log(active)
// console.log((currentSlide -1)/(circles.length-1)*100)
progress.style.width = ((currentSlide -1)/(circles.length-1))*100 +'%'
})
if(currentSlide == 1){
prev.disabled = true
}else if(currentSlide == circles.length){
next.disabled = true
}
else{
prev.disabled = false
next.disabled = false
}
}