-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (43 loc) · 1.17 KB
/
script.js
File metadata and controls
50 lines (43 loc) · 1.17 KB
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
const circles = document.querySelectorAll('.circle');
const nextButton = document.getElementById('next');
const prevButton = document.getElementById('prev');
const lineFill = document.querySelector('.line-fill');
let currentActive = 0;
nextButton.addEventListener('click', () => {
currentActive++;
if (currentActive > circles.length - 1) {
currentActive = circles.length - 1;
}
updateCircles();
});
prevButton.addEventListener('click', () => {
currentActive--;
if (currentActive < 0) {
currentActive = 0;
}
updateCircles();
});
function updateCircles() {
circles.forEach((circle, index) => {
if (index <= currentActive) {
circle.classList.add('active');
} else {
circle.classList.remove('active');
}
});
// Update the line fill
const progress = (currentActive / (circles.length - 1)) * 100;
lineFill.style.width = `${progress}%`;
// Disable buttons at start or end
if (currentActive === 0) {
prevButton.disabled = true;
} else {
prevButton.disabled = false;
}
if (currentActive === circles.length - 1) {
nextButton.disabled = true;
} else {
nextButton.disabled = false;
}
}
updateCircles(); // Initialize