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