使用animateTransform时如何指定xy旋转点?
我想使用 animateTransform 连续旋转 SVG 图像。所以我们开始吧:
<?xml version="1.0" encoding="utf-8"?>
<!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="1024px" height="768px" enable-background="new 0 0 100 100" xml:space="preserve">
<g transform="translate(100, 100)">
<rect fill="#FE9FFF" width="100px" height="100px">
<animateTransform attributeName="transform" type="rotate"
from="0" to="360" dur="20s" repeatDur="indefinite"/>
</rect>
</g>
</svg>
这有效。
现在:我想更改上面的内容,以便块围绕其中心而不是左上角旋转。我知道,如果我想围绕其中心静态旋转块,我可以这样做:
<g transform="rotate(30, 50, 50)">
<rect fill="#FE9FFF" width="100px" height="100px">
</rect>
</g>
我的问题是 - 如何管理围绕块中心的连续动画旋转?我查看了 规范 和一些其他相关问题,但我在执行所提供的解释时遇到了困难。
提前致谢。
I want to use animateTransform to rotate an SVG image continuously. So here we go:
<?xml version="1.0" encoding="utf-8"?>
<!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="1024px" height="768px" enable-background="new 0 0 100 100" xml:space="preserve">
<g transform="translate(100, 100)">
<rect fill="#FE9FFF" width="100px" height="100px">
<animateTransform attributeName="transform" type="rotate"
from="0" to="360" dur="20s" repeatDur="indefinite"/>
</rect>
</g>
</svg>
This works.
Now: I would like to change the above, so that the block rotates around its center and not its top left corner. I know that if I want to rotate the block statically around its center, I can do this:
<g transform="rotate(30, 50, 50)">
<rect fill="#FE9FFF" width="100px" height="100px">
</rect>
</g>
My question is - how do I manage a continuous animated rotation around the block's center? I have looked at the spec and a couple of other related questions on SO, but I'm having trouble implementing the explanations supplied.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://www.w3.org/TR/SVG/animate.html#AnimateTransformElement
如果提供 2 个附加值 cx 和 cy,则可以指定旋转中心。
因此,对于您的代码,我在“from”和“to”属性中添加“50 50”:
它适用于最新版本的 Opera、Safari 和 Chrome,还有 Firefrox 4 Beta 和 Batik。
http://www.w3.org/TR/SVG/animate.html#AnimateTransformElement
You can specify the center for the rotation if you provide 2 additional values, cx and cy.
So, for your piece of code, I add "50 50" in the "from" and "to" attribute :
It work with latest version of Opera, Safari and Chrome, also Firefrox 4 Beta and Batik.
需要明确的是:我们试图实现的是围绕一个本身正在平移的中心旋转。我发现如果我有一个,我就不能使用,也不能使用。进行同声翻译。它(最新的 Chrome 或 Firefox)不会根据需要插入旋转中心,从而导致“循环循环”。然而,使用简单的对于每个 x,y 坐标确实按预期工作;在这种情况下,沿 x,y 路径插值中心,只要将 from= 参数设置为起始角度、起始 x 和起始 y 位置,并将 to= 参数设置为结束值即可。
To be clear: what we are trying to achieve is rotation around a center which is itself being translated. I find that if I have an <animateTransform type=rotate>, I cannot use <animateMotion>, nor <animateTransform type=translate> to perform simultaneous translation. It (latest Chrome or Firefox) does not interpolate the center of rotation as desired, resulting in a "loop de loop" instead. However, using a simple <animate> for each of the x,y coordinates does work as desired; in this case, <animateTransform type=rotate> interpolates the center along the x,y path, as long as you set the from= parameter to the start angle, start x and start y position, and set the to= parameter to the ending values.