-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
54 lines (46 loc) · 1.28 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
const prevBtns = document.querySelectorAll(".btn-prev");
const nextBtns = document.querySelectorAll(".btn-next");
const progress = document.getElementById("progress");
const formSteps = document.querySelectorAll(".form-step");
const progressSteps = document.querySelectorAll(".progress-step");
let formStepsNum = 0;
nextBtns.forEach((btn) => {
btn.addEventListener("click", () => {
formStepsNum++;
updateFormSteps();
updateProgressbar();
});
});
prevBtns.forEach((btn) =>
{
btn.addEventListener("click", () =>
{
formStepsNum--;
updateFormSteps();
updateProgressbar();
});
});
function updateFormSteps()
{
formSteps.forEach((formStep) =>
{
formStep.classList.contains("form-step-active") && formStep.classList.remove("form-step-active");
});
formSteps[formStepsNum].classList.add("form-step-active");
}
function updateProgressbar()
{
progressSteps.forEach((progressStep, idx) =>
{
if (idx < formStepsNum + 1)
{
progressStep.classList.add("progress-step-active");
}
else
{
progressStep.classList.remove("progress-step-active");
}
});
const progressActive = document.querySelectorAll(".progress-step-active");
progress.style.width = ((progressActive.length - 1) / (progressSteps.length - 1)) * 100 + "%";
}