parent
66fa8ad6d1
commit
45b1577793
@ -1,49 +1,44 @@
|
|||||||
const progress = document.getElementById('progress')
|
const progress = document.getElementById('progress');
|
||||||
const prev = document.getElementById('prev')
|
const prev = document.getElementById('prev');
|
||||||
const next = document.getElementById('next')
|
const next = document.getElementById('next');
|
||||||
const circles = document.querySelectorAll('.circle')
|
const circles = document.querySelectorAll('.circle');
|
||||||
|
|
||||||
let currentActive = 1
|
let currentActive = 1;
|
||||||
|
|
||||||
next.addEventListener('click', () => {
|
next.addEventListener('click', () => {
|
||||||
currentActive++
|
currentActive++;
|
||||||
|
|
||||||
if (currentActive > circles.length) {
|
if (currentActive > circles.length) {
|
||||||
currentActive = circles.length
|
currentActive = circles.length;
|
||||||
}
|
}
|
||||||
|
update();
|
||||||
update()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
prev.addEventListener('click', () => {
|
prev.addEventListener('click', () => {
|
||||||
currentActive--
|
currentActive--;
|
||||||
|
|
||||||
if (currentActive < 1) {
|
if (currentActive < 1) {
|
||||||
currentActive = 1
|
currentActive = 1;
|
||||||
}
|
}
|
||||||
|
update();
|
||||||
update()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
circles.forEach((circle, idx) => {
|
circles.forEach((circle, idx) => {
|
||||||
if (idx < currentActive) {
|
if (idx < currentActive) {
|
||||||
circle.classList.add('active')
|
circle.classList.add('active');
|
||||||
} else {
|
} else {
|
||||||
circle.classList.remove('active')
|
circle.classList.remove('active');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const actives = document.querySelectorAll('.active')
|
const actives = document.querySelectorAll('.active');
|
||||||
|
progress.style.width = ((actives.length - 1) / (circles.length - 1)) * 100 + '%';
|
||||||
progress.style.width = (actives.length - 1) / (circles.length - 1) * 100 + '%'
|
|
||||||
|
|
||||||
if (currentActive === 1) {
|
if (currentActive === 1) {
|
||||||
prev.disabled = true
|
prev.disabled = true;
|
||||||
} else if (currentActive === circles.length) {
|
} else if (currentActive === circles.length) {
|
||||||
next.disabled = true
|
next.disabled = true;
|
||||||
} else {
|
} else {
|
||||||
prev.disabled = false
|
prev.disabled = false;
|
||||||
next.disabled = false
|
next.disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue