【发布时间】:2023-04-03 09:07:02
【问题描述】:
我一直在尝试使用 css 为 svg 矩形的宽度设置动画,它似乎可以与 chrome 和 opera 一起使用,但不能在 Firefox 中使用,我将不胜感激,在此先感谢
https://codepen.io/goprime/pen/BOPBjM
这是代码:
HTML:
<?xml version="1.0" standalone="no"?>
<!-- Generator: Gravit.io --><svg class="responsive-svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" style="isolation:isolate" viewBox="908.444 448 948 1114"
width="948" height="1114">
<!-- This is the main background -->
<g>
<rect x="908.444" y="448" width="948" height="1114" transform="matrix(1,0,0,1,0,0)" fill="white" />
<g transform="matrix(1,0,0,1,1232.227,773.652)">
<text transform="matrix(1,0,0,1,0,76.957)" style="font-family:'Source Sans Pro';font-weight:400;font-size:72px;font-style:normal;fill:#A4A598;stroke:none;">INTERIOR</text></g>
</g>
<!-- First box cover-->
<rect class="anim_test_top" x="1130" y="773.652" transform="matrix(1,0,0,1,0,0) rotate(180 1430 820.652)"
fill="white" />
</svg>
CSS:
.anim_test_top {
/* stroke:cyan; */
width: 530px;
height: 80px;
animation: anim 2s linear forwards;
}
@keyframes anim {
from {
width: 630.214px;
}
to {
width: 0;
}
}
【问题讨论】:
-
转换为 SMIL。在 Firefox 中,矩形元素的宽度/高度不是 CSS 属性。
-
@RobertLongson 嗨,谢谢你的回复,我还有一个问题,如果我保持当前代码不变,并为 firefox 添加 SMIL 部分可以吗?有没有办法让我指定 smil 代码只在 firefox 中工作?
-
这是你的代码,做你喜欢的事。 Chrome/Opera 支持 SMIL。
-
@RobertLongson 知道了,非常感谢您的帮助,我还有一个小问题,所以我用 SMIL 创建了动画,但是动画完成了,它恢复为它的原始状态,有没有办法让它保持动画结束时的状态?
-
添加填充="冻结"
标签: css svg css-animations