Animation 是 CSS3 属性中,除了 transform、transiton 以外的一个动画属性。css
具体有:animation-name、animation-duration、animation-timing-function、animation-delay、animation-iteration-count、animation-direction、animation-fill-mode、animation-play-state。html
语法: animation-name: none | index;
规定须要绑定到选择器的 keyframe 名称。浏览器
能够为动画变化的关键位置设置必定的顺序。动画
它的规则是 @keyframes 名称 {...} (注意要加 s,否则没法识别规则。)ui
有两种写法,一种是 0% - 100%,中间能够建立多个百分比给元素加上动画效果。spa
假设自定义 keyfram 名称为:index3d
@keyframes index {
0% {
/* ... */
}
50% {
/* ... */
}
100% {
/* ... */
}
}
复制代码
另一种写法是,from - to,from 至关于 0%,to 至关于100%,中间正常添加百分比。code
@keyframes index {
from {
/* ... */
}
50% {
/* ... */
}
to {
/* ... */
}
}
复制代码
语法: animation-duration: time;
orm
规定完成动画所花费的时间**(持续时间)**,单位为秒或毫秒。cdn
语法: animation-timing-function:ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(number, number, number, number) [, ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(number, number, number, number)]*
规定动画的速度曲线。
语法: animation-delay: time;
规定在动画开始以前的延迟时间,单位为秒或毫秒。
语法: animation-iteration-count: infinite | number;
规定动画应该反复播放的次数**(迭代次数)**。
语法: animation-direction: normal | reverse | alternate | alternate-reverse;
规定动画播放的方向。
normal:默认值,正向播放。
reverse:反向播放。
alternate:偶数次反向播放、奇数次正向播放。
alternate-reverse:奇数次反向播放、偶数次正向播放。
语法: animation-fill-mode: none | forwards | backwards | both;
规定动画在播放以前或以后,其动画效果是否可见。
none:不改变默认行为。
forwards:当动画完成后,保持最后一个属性值(在最后一个关键帧中定义)。
backwards:在 animation-delay 所指定的一段时间内,在动画显示以前,应用开始属性值(在第一个关键帧中定义)。
both:向前和向后填充模式都被应用。
语法: animation-play-state: running | paused
规定动画正在运行仍是暂停,即控制动画播放状态。
running:默认值,动画正常播放。
paused:动画暂停。
<div class="box">Animation</div>
复制代码
.box {
width: 100px;
height: 100px;
background-color: pink;
animation: index 2s ease-in .2s 3 normal both;
}
/* @keyframes index { 0% { width: 200px; } 50% { height: 200px; } 100% { transform: rotate(180deg) } } */
@keyframes index {
from {
width: 200px;
}
50% {
height: 200px;
}
to {
transform: rotate(180deg);
}
}
复制代码