-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (35 loc) · 1.04 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');
const update = () => {
circles.forEach((circle, i) => {
i < currActive ? circle.classList.add('active') : circle.classList.remove('active');
});
const actives = document.querySelectorAll('.active');
const width = (actives.length - 1) / (circles.length - 1) *100;
progress.style.width = `${width}%`;
if (currActive ===1) {
prev.disabled = true;
} else if (currActive === circles.length) {
next.disabled = true;
} else {
prev.disabled = false;
next.disabled = false;
}
};
let currActive = 1;
next.addEventListener('click', () => {
currActive++;
if (currActive > circles.length) {
currActive = circles.length;
}
update();
});
prev.addEventListener('click', () => {
currActive--;
if (currActive < 1) {
currActive = 1;
}
update();
});