|
1 | | -const progress = document.getElementById("progress"); |
2 | | -const prev = document.getElementById("prev"); |
3 | | -const next = document.getElementById("next"); |
4 | | -const circles = document.querySelectorAll(".circle"); |
| 1 | +"use strict"; |
5 | 2 |
|
6 | | -let currentActive = 1; |
| 3 | +// select all elements i need |
| 4 | +const circles = document.querySelectorAll(".circle"); |
| 5 | +const lines = document.querySelectorAll(".line"); |
| 6 | +const prevBtn = document.querySelector(".prev"); |
| 7 | +const nextBtn = document.querySelector(".next"); |
7 | 8 |
|
8 | | -next.addEventListener("click", () => { |
9 | | - currentActive++; |
10 | | - if (currentActive > circles.length) currentActive = circles.length; |
11 | | - update(); |
12 | | -}); |
| 9 | +let whichNumber = 0; |
13 | 10 |
|
14 | | -prev.addEventListener("click", () => { |
15 | | - currentActive--; |
16 | | - if (currentActive < 1) currentActive = 1; |
17 | | - update(); |
| 11 | +// Next Event |
| 12 | +nextBtn.addEventListener("click", (e) => { |
| 13 | + if (whichNumber < 3) { |
| 14 | + whichNumber++; |
| 15 | + prevBtn.classList.add("active-btn"); |
| 16 | + circles[whichNumber].classList.add("active-circle"); |
| 17 | + lines[whichNumber - 1].classList.add("active-line"); |
| 18 | + } |
| 19 | + if (whichNumber == 3) { |
| 20 | + nextBtn.classList.remove("active-btn"); |
| 21 | + return; |
| 22 | + } |
18 | 23 | }); |
19 | 24 |
|
20 | | -const update = () => { |
21 | | - circles.forEach((circle, index) => { |
22 | | - if (index < currentActive) circle.classList.add("active"); |
23 | | - else circle.classList.remove("active"); |
24 | | - }); |
25 | | - const actives = document.querySelectorAll(".active"); |
26 | | - progress.style.width = |
27 | | - ((actives.length - 1) / (circles.length - 1)) * 100 + "%"; |
28 | | - if (currentActive === 1) prev.disabled = true; |
29 | | - else if (currentActive === circles.length) next.disabled = true; |
30 | | - else { |
31 | | - prev.disabled = false; |
32 | | - next.disabled = false; |
| 25 | +// Prev Event |
| 26 | +prevBtn.addEventListener("click", (e) => { |
| 27 | + if (whichNumber > 0) { |
| 28 | + nextBtn.classList.add("active-btn"); |
| 29 | + circles[whichNumber].classList.remove("active-circle"); |
| 30 | + lines[whichNumber - 1].classList.remove("active-line"); |
| 31 | + whichNumber--; |
| 32 | + } |
| 33 | + if (whichNumber == 0) { |
| 34 | + prevBtn.classList.remove("active-btn"); |
| 35 | + return; |
33 | 36 | } |
34 | | -}; |
| 37 | +}); |
0 commit comments