-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (30 loc) · 971 Bytes
/
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
const progress = document.querySelector(".progress");
const steps = document.querySelectorAll(".step");
const prevBtn = document.querySelector(".prev");
const nextBtn = document.querySelector(".next");
let step = 0;
prevBtn.addEventListener("click", () => updateStep(-1));
nextBtn.addEventListener("click", () => updateStep(1));
function updateStep(direction) {
step += direction;
if (step >= 0 && step < steps.length) {
updateProgressBar();
updateStepDisplay();
updateButtonState();
}
}
function updateProgressBar() {
const multiplier = 100 / (steps.length - 1);
const width = step * multiplier;
progress.style.transform = `scaleX(${width}%)`;
}
function updateStepDisplay() {
steps.forEach((s, index) => {
s.classList.toggle("active", index <= step);
s.textContent = index + 1 <= step ? "✓" : index + 1;
});
}
function updateButtonState() {
prevBtn.disabled = step === 0;
nextBtn.disabled = step === steps.length - 1;
}