-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
57 lines (48 loc) · 1.58 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
const nextEl = document.getElementById("next");
const prevEl = document.getElementById("prev");
const progressEl = document.querySelector(".progress-bar-front");
const stepEl = document.querySelectorAll(".step");
let currentChecked = 1;
console.log(stepEl.length);
nextEl.addEventListener("click", () => {
currentChecked++;
if (currentChecked > stepEl.length) {
currentChecked = stepEl.length;
}
updateStepProgress();
});
prevEl.addEventListener("click", () => {
currentChecked--;
if (currentChecked < 1) {
currentChecked = 1;
}
updateStepProgress();
});
const updateStepProgress = () => {
stepEl.forEach((step, idx) => {
if (idx < currentChecked) {
step.classList.add("checked");
console.log(idx);
step.innerHTML = `
<i class="fas fa-check"></i>
<small>
${idx === 0 ? "Start" : idx === stepEl.length - 1 ? "Final" : "Step " + idx}
</small>`;
} else {
step.classList.remove("checked");
step.innerHTML = `<i class="fas fa-times"></i>`;
}
});
const checkedNumber = document.querySelectorAll(".checked").length;
progressEl.style.width = ((checkedNumber - 1) / (stepEl.length - 1)) * 100 + "%";
if (currentChecked === 1) {
prevEl.disabled = true;
} else if (currentChecked === stepEl.length) {
nextEl.disabled = true;
} else {
prevEl.disabled = false;
nextEl.disabled = false;
}
};
// Initial call to disable the "Previous" button if on the first step
updateStepProgress();