Skip to content

Commit f820b6f

Browse files
committed
add prev and next button functionalities
1 parent 5b4b4c8 commit f820b6f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Diff for: ProgressSteps/script.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const progress = document.getElementById('progress');
2+
const prev = document.getElementById('prev');
3+
const next = document.getElementById('next');
4+
const circles = document.querySelectorAll('.circle');
5+
6+
let currentActive = 1;
7+
8+
const update = () => {
9+
circles.forEach((circle, index) => {
10+
if (index < currentActive) {
11+
circle.classList.add('active');
12+
} else {
13+
circle.classList.remove('active');
14+
}
15+
});
16+
const actives = document.querySelectorAll('.active');
17+
progress.style.width = `${
18+
((actives.length - 1) / (circles.length - 1)) * 100
19+
}%`;
20+
21+
if (currentActive === 1) {
22+
prev.disabled = true;
23+
} else if (currentActive === circles.length) {
24+
next.disabled = true;
25+
} else {
26+
prev.disabled = false;
27+
next.disabled = false;
28+
}
29+
};
30+
31+
next.addEventListener('click', () => {
32+
currentActive += 1;
33+
if (currentActive > circles.length) {
34+
currentActive = circles.length;
35+
}
36+
update();
37+
});
38+
39+
prev.addEventListener('click', () => {
40+
currentActive -= 1;
41+
if (currentActive < 1) {
42+
currentActive = 1;
43+
}
44+
update();
45+
});

0 commit comments

Comments
 (0)