如何在使用animateTransform时指定xy旋转点?

8 animation svg transform rotation

我想使用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>
Run Code Online (Sandbox Code Playgroud)

这有效.

现在:我想改变上面的内容,以便块围绕其中心而不是左上角旋转.我知道如果我想围绕其中心静态旋转块,我可以这样做:

<g transform="rotate(30, 50, 50)">
  <rect fill="#FE9FFF" width="100px" height="100px">
  </rect>
</g>
Run Code Online (Sandbox Code Playgroud)

我的问题是 - 如何管理块中心周围的连续动画旋转?我已经查看了关于SO 的规范其他几个相关问题,但是我无法实现所提供的解释.

提前致谢.

Pla*_*lan 11

http://www.w3.org/TR/SVG/animate.html#AnimateTransformElement

'from','by'和'to'属性采用可用于给定转换类型的相同语法表示的值:
(...)
对于type ="rotate",每个单独的值表示为<旋转角度> [<cx> <cy>]

如果提供2个附加值cx和cy,则可以指定旋转中心.

因此,对于您的代码,我在"from"和"to"属性中添加"50 50":

<rect fill="#FE9FFF" width="100px" height="100px">
    <animateTransform attributeName="transform" type="rotate"
        from="0 50 50" to="360 50 50" dur="20s" repeatDur="indefinite"/>
</rect>
Run Code Online (Sandbox Code Playgroud)

它适用于最新版本的Opera,Safari和Chrome,以及Firefrox 4 Beta和Batik.