
css 中如何保持动画后的样式
想要保持动画后的样式,需要修改 html 和 css 代码。
在提供的 html 代码中,存在如下问题:
这个
立即学习“前端免费学习笔记(深入)”;
要解决这个问题,需要在 html 代码中添加一个初始位置:
接下来,在 css 代码中修改动画的结束属性:
.out { animation: out 1s; animation-fill-mode: forwards;}
animation-fill-mode: forwards 确保动画在结束时保持结束属性值。
修改后的 css 代码如下:
.box { width: 100px; height: 100px; position: absolute;}.box-in { background-color: blue; opacity: 0;}.box-out { background-color: red; opacity: 1;}.out { animation: out 1s; animation-fill-mode: forwards;}.in { animation: in 1s;}@keyframes out { from { left: -70px; } to { left: 70px; opacity: 0; }}@keyframes in { from { left: 70px; } to { left: 0px; opacity: 1; }}
现在,动画结束后,div 将保留其 ending position。
以上就是CSS 动画后如何保持样式不变?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1630360.html
微信扫一扫
支付宝扫一扫