具体使用示例:
1.通过transition设置过渡,添加transform设置形状,实现动画效果。
.divadd {
transition: All 0.4s ease-in-out;
-webkit-transition: All 0.4s ease-in-out;
-moz-transition: All 0.4s ease-in-out;
-o-transition: All 0.4s ease-in-out;
transform:rotate(360deg);
-ms-transform:rotate(360deg); /* IE 9 */
-webkit-transform:rotate(360deg); /* Safari and Chrome */
}
2.添加animation属性,实现动画效果。
.a1 {
position: absolute;
animation: a1 3s;
opacity: 0
}
@keyframes a1 {
0% {left: 10px;opacity: 0}
30% {left: 60px;background-color: pink;font-size:23px;opacity: 1}
90% {left: 100px;background-color: red;opacity: 1}
100% {left: 10px;opacity: 0}
}
相关属性:
animation-name: myfirst; //动画名称,用于animation引用
animation-duration: 5s; //动画时长,
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-play-state: running;
属性分析:
animation-fill-mode
设置动画结束后的状态
none:默认值。不设置对象动画之外的状态,DOM未进行动画前状态
forwards:设置对象状态为动画结束时的状态,100%或to时,当设置animation-direcdtion为reverse时动画结束后显示为keyframes第一帧
backwards:设置对象状态为动画开始时的状态,测试显示DOM未进行动画前状态
both:设置对象状态为动画结束或开始的状态,结束时状态优先