CSS加载动画效果
Posted 森森子_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSS加载动画效果相关的知识,希望对你有一定的参考价值。
哈喽!俺又来了,马上就要8月份了,时间仿佛在对我说:“暑假?拿来吧你”🙃又是学习css和js的一天,在刷小视频加载时经常看到一些加载动画,简单上手了css3新增的动画后,就想仿写一个加载效果,就是玩哈哈,开整!
效果:
1. 分析元素
可以看到这个简单的特效由5个块通过延时差形成的,能给人一种再等等的想法。很不错,设计yyds。
5个块我们用5个盒子实现,配合CSS3的动画关键帧以及伪类选择器实现延时差即可实现。有一个好的分析和思路,可以减少你的coding出错率和time,🆗,coding吧!!!
2.html部分
这就是爸爸管着5个儿子,不用多说了
<!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部分
CSS3的结构伪类选择器控制 匹配除了第一个以外的儿子,延时产生感觉,哈哈,为啥不可以直接写在一个里好比.box>div:nth-child(2,3,4,5){ animation-delay: -1s; }
不懂,可能还需要完善吧!我是这样想的
.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>
是不是很简单,写京东的项目受到打击了,还是慢慢来吧!是要有一个过程的,加油~🆗,就到这,下课,拜拜了你!
以上是关于CSS加载动画效果的主要内容,如果未能解决你的问题,请参考以下文章