-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (39 loc) · 1.03 KB
/
Copy pathindex.js
File metadata and controls
44 lines (39 loc) · 1.03 KB
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
const progressBar = document.getElementById('progress')
const prev = document.getElementById('prev')
const next = document.getElementById('next')
const circles = document.querySelectorAll('.circle')
let currentStep = 1;
prev.addEventListener('click',()=>{
currentStep--
if(currentStep < 1){
currentStep = 1
}
update()
})
next.addEventListener('click',()=>{
currentStep++
if(currentStep > circles.length){
currentStep = circles.length
}
update()
})
function update(){
circles.forEach((circle,index)=>{
if(index < currentStep){
circle.classList.add('active')
}else{
circle.classList.remove('active')
}
})
const progressStatus = (currentStep-1)/ (circles.length-1)
// debugger
progressBar.style.width = progressStatus*100 + '%'
if(currentStep === circles.length){
next.disabled = true
}else if (currentStep === 1){
prev.disabled = true
}else{
next.disabled = false
prev.disabled = false
}
}