parent
66fa8ad6d1
commit
45b1577793
@ -1,24 +1,27 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<link rel="stylesheet" href="style.css" />
|
|
||||||
<title>Progress Steps</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<div class="progress-container">
|
|
||||||
<div class="progress" id="progress"></div>
|
|
||||||
<div class="circle active">1</div>
|
|
||||||
<div class="circle">2</div>
|
|
||||||
<div class="circle">3</div>
|
|
||||||
<div class="circle">4</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button class="btn" id="prev" disabled>Prev</button>
|
<head>
|
||||||
<button class="btn" id="next">Next</button>
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
<title>Progress Steps</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="progress-container">
|
||||||
|
<div class="progress" id="progress"></div>
|
||||||
|
<div class="circle active">1</div>
|
||||||
|
<div class="circle">2</div>
|
||||||
|
<div class="circle">3</div>
|
||||||
|
<div class="circle">4</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="script.js"></script>
|
|
||||||
</body>
|
<button class="btn" id="prev" disabled>Prev</button>
|
||||||
|
<button class="btn" id="next">Next</button>
|
||||||
|
</div>
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
@ -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