现象:
使用 animation-timing-funciton:steps()
添加 animation-fill-mode:forwards 动画效果最后一步能够实现,无此属性则最后一步效果不显示
请问相关原因是?
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
@keyframes CFR {
0% {
width: 0;
}
100% {
width: 140px;
}
}
@keyframes CFR {
0% {
width: 0;
}
100% {
width: 120px;
}
}
.CFR {
width: 0;
height: 30px;
font-size: 20px;
background-color: #3460AB;
animation: CFR 3s steps(6) forwards;
white-space: nowrap;
overflow: hidden;
}
</style>
<body>
<div class="CFR">
一二三四五六
</div>
</body>
</html>
animation-fill-mode 设置forwards 会让元素在动画结束之后保持最后一帧的状态。
如果不设置forwards 动画结束之后,元素会回到进行动画之前的状态。 也就是 元素会回到 .CFR {中设置的 width: 0;的状态
如有帮助,望采纳!谢谢! 点击我这个回答右上方的【采纳】按钮