How to specify the x-y rotation point when using animateTransform?

前端 未结 2 2098
面向向阳花
面向向阳花 2021-02-14 21:15

I want to use animateTransform to rotate an SVG image continuously. So here we go:





        
相关标签:
2条回答
  • 2021-02-14 21:32

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

    The ‘from’, ‘by’ and ‘to’ attributes take a value expressed using the same syntax that is available for the given transformation type:
    (...)
    For a type="rotate", each individual value is expressed as <rotate-angle> [<cx> <cy>]

    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 :

    <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>
    

    It work with latest version of Opera, Safari and Chrome, also Firefrox 4 Beta and Batik.

    0 讨论(0)
  • 2021-02-14 21:48

    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.

    0 讨论(0)
提交回复
热议问题