动画会反转,因为您在关键帧定义中指定了50%,而默认的animation-fill-mode是none,因此动画将在最后重置。
相反,将关键帧定义为100%(或to),并应用forwards或animation-fill-mode:both
.dark1 {
background-color: black;
width: 50px;
height: 100vh;
position: absolute;
left: 0px;
top: 0px;
width: 50%;
animation: example1 5s;
animation-fill-mode: both;
}
@keyframes example {
100% {
right: -500px;
}
}
本文探讨了CSS动画中animation-fill-mode属性的作用,特别是在动画结束时元素的状态保持问题。通过一个具体的例子展示了如何设置关键帧及animation-fill-mode属性来避免动画结束后的元素状态回跳,并保持最终状态。
1113

被折叠的 条评论
为什么被折叠?



