按照动画的执行时间来划分,一次动画过程可以将元素划分为3个状态:动画等待,动画进行和动画结束状态。默认情况下,只有在动画进行状态,才会应用动画的keyframes所定义的样式;而在动画等待和动画结束状态,不会对元素的样式产生影响。animation-fill-mode有四个值,分别是:
none:这是默认值,正是这个值,使得动画不会对动画等待和动画完成的元素样式产生改变;
backwards:如果设置为这个值,那么在动画等待的那段时间内,元素的样式将设置为动画第一帧的样式;
forwards:如果设置为这个值,那么在动画结束后,元素的样式将设置为动画的最后一帧的样式;
both:相当于同时配置了backwards和forwards,意味着在动画等待和动画结束状态,元素将分别应用动画第一帧和最后一帧的样式。
通过下面的demo,可以感受下animation-fill-mode三个非none值的作用。
demo1:http://liuyunzhuge.github.io/blog/animation/dist/html/animation-fill-mode.html#demo1
效果如下:
less源码:
#demo1 { .target.animate { animation-name : move_1 ; animation-duration : 2s ; animation-delay : 1s ; &.target_1 { animation-fill-mode : backwards ; } &.target_2 { animation-fill-mode : forwards ; } &.target_3 { animation-fill-mode : both ; } } } @keyframes move_1 { 0% { transform : translate(-50px, 0) ; } 50% { transform : translate(0, 0) ; } 100% { transform : translate(50px, 0) ; } }
查看更多关于animation-fill-mode的一些思考的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did101977