CSS animation-fill-mode属性

animation-fill-mode属性

CSS中的animation-fill-mode属性,可以指定@keyframes定义的动画在播放之前或之后,其动画效果的可见性。


语法

animationo-direction:modeValue

可选属性值

属性值描述
none不改变默认行为
forwards在动画完成之后,保持最后一个属性值
backwards在动画开始之前,应用最开始的属性值
both向前以及向后两种填充模式都被应用

提示:alternate属性值会在动画播放的奇数次数正常播放,然后在偶数次数向后播放。


animation-fill-mode实例代码,及在线编辑器

<div id='d1'></div><br>
<div id='d2'></div>

<style>
@keyframes widthChange{
from   {width:25%;}
to  {width:100%;}

}


#d1{
width:25%;
height:80px;
background-color:skyblue;
animation:widthChange 3s;
animation-fill-mode:backwards;
}
  
#d2{
width:25%;
height:80px;
background-color:orange;
animation:widthChange 3s;
animation-fill-mode:forwards;
}
</style>

全栈前端 / CSS教程 :



























Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.