-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (40 loc) · 1.3 KB
/
index.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
const checkpoints = document.querySelectorAll(".circle");
const prev = document.querySelector("#prev");
const next = document.querySelector("#next");
const progress = document.querySelector("#progress");
let activeCurrent = 1;
next.addEventListener("click", () => {
activeCurrent < checkpoints.length ? activeCurrent++ : "";
update();
});
prev.addEventListener("click", () => {
activeCurrent > 1 ? activeCurrent-- : "";
update();
});
function update() {
checkpoints.forEach((checkpoint, indx) => {
if (indx < activeCurrent) {
checkpoint.classList.add("active");
} else {
checkpoint.classList.remove("active");
}
});
const actives = document.querySelectorAll(".active");
progress.style.width =
((actives.length - 1) / (checkpoints.length - 1)) * 100 + "%";
if (activeCurrent === 1) {
prev.disabled = true;
} else if (activeCurrent === checkpoints.length) {
next.disabled = true;
} else {
prev.disabled = false;
next.disabled = false;
}
}
const navOpen = document.querySelector("#open");
const navClose = document.querySelector("#close");
const container = document.querySelector("main");
navOpen.addEventListener("click", () => container.classList.add("nav-active"));
navClose.addEventListener("click", () =>
container.classList.remove("nav-active")
);