来源于技术胖的视频总结
1.动画中的关键帧@keyframes
demo 01
.demo{
width:100px;
height:100px;
background:palevioletred;
position:absolute;
/* 使用定义的动画,持续时间为2s,无限循环 */
animation: myname 2s infinite;
}
/* 定义动画 myname为随意定义的动画名称*/
@keyframes myname{
from {top:0;left:20%}
to {top:0;left:80%;}
}
demo 02
.demo{
width:100px;
height:100px;
background:palevioletred;
position:absolute;
/* 使用定义的动画,持续时间为5s,无限循环 */
animation: myname 5s infinite;
}
/* 定义动画 myname为随意定义的动画名称*/
@keyframes myname{
0% {top:0;left:20%;}
25% {top:0;left:80%;background:papayawhip}
50% {top:50%;left:80%;background:powderblue}
75% {top:50%;left:20%;background:darkgray}
100% {top:0;left:20%;background:beige}
}
2.animation
复合属性讲解
animation-name
:动画名称
animation-duration
:动画的持续时间
animation-timing-function
:与transition属性相同
animation-delay
:动画延迟几秒执行
anamation-iteration-count
:循环的次数
animation-direction
:normal(正常的)alternate(动画的饭方向播放)
3.实例Loading01
.demo{
margin:100px auto;
width:60px;
height:60px;
text-align: center;
font-size:10px;
}
.demo>div{
background: pink;
height:100%;
width:6px;
display: inline-block;
animation:myname 1.2s infinite ease;
}
.demo>div:nth-child(2){
animation-delay:-1.1s
}
.demo>div:nth-child(3){
animation-delay:-.9s
}
.demo>div:nth-child(4){
animation-delay:-.8s
}
.demo>div:nth-child(5){
animation-delay:-.7s
}
@keyframes myname{
0%,40%,80%{transform:scaleY(.4)}
20%{transform: scaleY(1)}
}
4.实例Loading02
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<script src="src/index.js"></script>
<title>Document</title>
<style>
.demo{
margin:100px auto;
width:60px;
height:60px;
position:relative;
}
.demo>div{
width:100%;
height:100%;
border-radius:50%;
background:blueviolet;
opacity:0.6;
position:absolute;
top:0px;
left:0px;
animation:myname 2s infinite ease;
}
.demo>div:nth-child(2){
animation-delay:-1s
}
@keyframes myname{
0%,100%{transform:scale(0.0)}
50%{transform: scale(1)}
}
</style>
</head>
<body>
<div class="demo">
<div></div>
<div></div>
</div>
</body>
</html>