运用了css变量的知识,直接上代码及其我加的注释
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>展示一个css动态条形加载条</title>
<style>
.flex {
display: flex;
list-style: none;
}
.loading {
width: 200px;
height: 200px;
}
.loading>li {
--time: calc((var(--line-index) - 1) * 200ms);
border-radius: 3px;
width: 6px;
height: 30px;
background-color: #f66;
animation: beat 1.5s ease-in-out var(--time) infinite;
}
.loading>li+li {
margin-left: 5px;
}
@keyframes beat {
0%,
100% {
transform: scaleY(1);
}
50% {
transform: scaleY(.5);
}
}
</style>
</head>
<body>
<ul class="loading flex">
<li style="--line-index: 1;"></li>
<li style="--line-index: 2;"></li>
<li style="--line-index: 3;"></li>
<li style="--line-index: 4;"></li>
<li style="--line-index: 5;"></li>
<li style="--line-index: 6;"></li>
</ul>
</body>
</html>
看效果
非常漂亮和顺畅