进度条
2.
3.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>进度条</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="container">
<div class="container-progress">
<div class="step active">
<span>1</span>
</div>
<div class="line"></div>
<div class="step">
<span>2</span>
</div>
<div class="line"></div>
<div class="step">
<span>3</span>
</div>
<div class="line"></div>
<div class="step">
<span>4</span>
</div>
</div>
<button disabled>pre</button>
<button>next</button>
</div>
<script src="index.js"></script>
</body>
</html>
css
*{
margin:0;
padding:0;
}
body{
display: flex;
justify-content: center;
align-items: center;
height: 90vh;
}
.container{
text-align: center;
.container-progress{
display: flex;
.step{
box-sizing: border-box;
width: 43px;
height: 43px;
border: 3px solid #e0e0e0;
border-radius: 50%;
text-align: center;
line-height: 40px;
}
.line{
width: 50px;
height: 2px;
background: #e0e0e0;
margin: 20px 0;
}
.active{
background: #3498db;
border: #3498db;
transition: background-color ease-in 0.7s;
}
}
button{
width: 80px;
height: 40px;
margin: 30px;
color: #fff;
border:0;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
background-color: #3498db;
}
button:active{
transform: scale(0.98);
}
button:focus{
outline: 0;
}
button:disabled{
background-color: #e0e0e0;
cursor: not-allowed;
}
}
js
window.onload = function (){
const circle = document.getElementsByClassName('step');
const line = document.getElementsByClassName('line');
const btns = document.getElementsByTagName('button');
const pre = btns[0], next = btns[1];
let index = 0;
next.onclick = function (){
line[index].classList.add('active');
circle[index+1].classList.add('active');
index++;
if(index!=0){
pre.disabled = false;
}
if(index==3){
next.disabled = true;
}
}
pre.onclick = function (){
line[index-1].classList.remove('active');
circle[index].classList.remove('active');
index--;
if(index!=3){
next.disabled = false;
}
if(index==0){
pre.disabled = true;
}
}
}