1. 分析元素
可以看到这个简单的特效由5个块通过延时差形成的,能给人一种再等等的想法。很不错,设计yyds。
5个块我们用5个盒子实现,配合CSS3的动画关键帧以及伪类选择器实现延时差即可实现。有一个好的分析和思路,可以减少你的coding出错率和time,🆗,coding吧!!!
2.html部分
<!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>
</head>
<body>
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>
3.CSS部分
.box{
margin: 200px auto;
width: 50px;
height: 50px;
text-align: center;
font-size: 10px;
}
.box > div{
background-color: rgba(64, 219, 25,0.9);
width: 5px;
height: 100%;
/* 行内块 */
display: inline-block;
/* 名字 执行时间 一直执行 先慢再快再慢 */
animation: move 1.2s infinite ease-in-out;
}
/* 定义关键帧 */
@keyframes move{
0%{transform: scaleY(0.4);}
40%{transform: scaleY(0.4);}
60%{transform: scaleY(0.4);}
80%{transform: scaleY(0.4);}
100%{transform: scaleY(0.4);}
20%{transform: scaleY(1);}
}
/* 伪类选择器控制 匹配除了第一个以外的儿子,延时产生感觉*/
.box>div:nth-child(2){
animation-delay: -1s;
}
.box>div:nth-child(3){
animation-delay: -0.9s;
}
.box>div:nth-child(4){
animation-delay: -0.8s;
}
.box>div:nth-child(5){
animation-delay: -0.7s;
}
4.完整代码
<!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>
<style>
.box{
margin: 200px auto;
width: 50px;
height: 50px;
text-align: center;
font-size: 10px;
}
.box > div{
background-color: rgba(64, 219, 25,0.9);
width: 5px;
height: 100%;
/* 行内块 */
display: inline-block;
/* 名字 执行时间 一直执行 先慢再快再慢 */
animation: move 1.2s infinite ease-in-out;
}
/* 定义关键帧 */
@keyframes move{
0%{transform: scaleY(0.4);}
40%{transform: scaleY(0.4);}
60%{transform: scaleY(0.4);}
80%{transform: scaleY(0.4);}
100%{transform: scaleY(0.4);}
20%{transform: scaleY(1);}
}
.box>div:nth-child(2){
animation-delay: -1s;
}
.box>div:nth-child(3){
animation-delay: -0.9s;
}
.box>div:nth-child(4){
animation-delay: -0.8s;
}
.box>div:nth-child(5){
animation-delay: -0.7s;
}
</style>
</head>
<body>
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>