-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (38 loc) · 1.09 KB
/
app.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
const progress = document.querySelector('#progress');
const prev = document.querySelector('#prev');
const next = document.querySelector('#next');
const circles = document.querySelectorAll('.circle');
let currentActive = 1;
next.addEventListener('click', function () {
currentActive++;
if (currentActive > circles.length) {
currentActive = circles.length
}
update()
})
prev.addEventListener('click', function () {
currentActive--;
if (currentActive < 1) {
currentActive = 1
}
update()
})
function update() {
circles.forEach((circle, idx) => {
if (idx < currentActive) {
circle.classList.add('active');
} else {
circle.classList.remove('active')
}
})
const active = document.querySelectorAll('.active')
progress.style.width = (active.length - 1) / (circles.length - 1) * 100 + '%'
if (currentActive === 1) {
prev.disabled = true
} else if (currentActive === circles.length) {
next.disabled = true;
} else {
prev.disabled = false;
next.disabled = false;
}
}