SVG animateTransform 同时旋转和缩放同一个对象?

标签 svg jquery-animate smil

我想同时对缩放和旋转对象进行动画处理。到目前为止,我的尝试失败了。我只能链接动画(旋转,然后缩放)但不能一起旋转和缩放。

我错过了什么?

我试图删除“additive =“sum”,但这只是覆盖并忽略了缩放动画......

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
 width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">

<rect x="29.2" y="33.6" width="136.7" height="136.7">

<animateTransform attributeName="transform" type="scale" 
from="0" to="1" dur="1s" additive="sum" accumulate="sum"/> 

<animateTransform attributeName="transform" type="rotate" 
from="0 100 100" to="100 100 100" dur="5s"  repeatCount="indefinite"  accumulate="sum" />


<animate attributeType="CSS" attributeName="opacity" 
from="1" to="0" dur="4s" fill="freeze"  />


</rect>
</svg>

我感谢所有的帮助!

最佳答案

您只需要在两个 animate 元素上添加 add="sum"即可。通过这一更改,它在 Firefox 上对我来说效果很好。

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
 width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">

<rect x="29.2" y="33.6" width="136.7" height="136.7">

<animateTransform attributeName="transform" type="scale" 
from="0" to="1" dur="1s" additive="sum" accumulate="sum"/> 

<animateTransform attributeName="transform" type="rotate" 
from="0 100 100" to="100 100 100" dur="5s"  repeatCount="indefinite"  additive="sum" accumulate="sum" />


<animate attributeType="CSS" attributeName="opacity" 
from="1" to="0" dur="4s" fill="freeze"  />


</rect>
</svg>

关于SVG animateTransform 同时旋转和缩放同一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27829312/

相关文章:

javascript - 外部 SVG Sprite 和 .childnodes

javascript - SVG 矩形宽度不一致

jQuery简单左右动画

SVG animateTransform 翻译和缩放同时失败

html - 用背景图像填充 SVG 路径元素

html - SVG 模式在 Safari 中不起作用

javascript - 当 CSS 动画在视口(viewport)之外时,我应该停止它们吗

javascript - 使用 Canvas 为圆环图中的线条设置动画

javascript - 是否可以从 javascript 访问 SMIL 计时器?

css - SMIL 动画不在 Mouseout 上结束