-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (51 loc) · 1.33 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
56
57
58
59
60
61
62
63
64
const progress = document.getElementById("progress");
const prev = document.getElementById("prev");
const next = document.getElementById("next");
const circles = document.querySelectorAll(".circle");
let step = 1;
function main() {
// Update circles with "active" class based on the current step
circles.forEach((circle, index) => {
if (index < step) {
circle.classList.add("active");
} else {
circle.classList.remove("active");
}
});
// Recalculate active elements AFTER updating the circles
let actives = document.querySelectorAll(".active");
// Update progress bar width based on active circles
progress.style.width = `${
((step - 1) / (circles.length - 1)) * 100
}%`;
console.log(progress.style.width);
console.log(actives.length);
console.log(circles.length);
// Enable/disable buttons based on the current step
if (step === 1) {
prev.disabled = true;
} else if (step === circles.length) {
next.disabled = true;
} else {
prev.disabled = false;
next.disabled = false;
}
}
// Next Button
next.addEventListener("click", () => {
step++;
if (step > circles.length) {
step = circles.length;
}
main();
});
// Previous Button
prev.addEventListener("click", () => {
step--;
if (step < 1) {
step = 1;
}
main();
});
// Initialize progress tracker
main();