逻辑
给父元素设置一个大于子元素的高,然后通过设置子元素的统一动画关键帧,让它们实现统一运动,然后通过设置每个子元素的动画延迟(animation-delay),达到不同运动的效果。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>简单条状加载页面</title>
<!--
逻辑:给父元素一个大于子元素的高,然后通过设置子元素的统一动画关键帧,让它们实现统一运动,
然后通过设置每个子元素的动画延迟(animation-delay),达到不同运动的效果。
-->
<style>
.box {
height: 200px;
display: flex;
justify-content: center;
align-items: center;
}
.box div {
width: 25px;
margin-right: 30px;
animation: dong 1s linear infinite;
}
@keyframes dong {
0%, 100% {
height: 100px;
}
20% {
height: 80px;
}
40%{
height: 60px;
}
60% {
height: 40px;
}
80% {
height: 20px;
}
}
.box div:nth-child(1) {
animation-delay: 0.2s;
background-color: orange;
}
.box div:nth-child(2) {
animation-delay: 0.4s;
background-color: green;
}
.box div:nth-child(3) {
animation-delay: 0.6s;
background-color: aqua;
}
.box div:nth-child(4) {
animation-delay: 0.8s;
background-color: purple;
}
.box div:nth-child(5) {
animation-delay: 1s;
background-color: blue;
}
</style>
</head>
<body>
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>