How to loop SVG animation sequence?
Asked Answered
S

3

32

I have sequence of animationTransform:

<animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0" to="30" begin="0s" dur="0.4s" fill="freeze"/>
<animateTransform attributeName="transform" attributeType="XML" type="rotate" from="30" to="0" begin="0.4s" dur="0.4s" fill="freeze"/>

If it possible to loop this sequence without using script?

I can set individual animation to loop by using repeatCount="indefinite" by I want to loop the whole sequence in order.

Stomatic answered 2/9, 2010 at 18:21 Comment(0)
S
46

Figured it out already. Solution for those who are interested:

<animateTransform id="anim1" attributeName="transform" attributeType="XML" type="rotate" from="0" to="30" begin="0s; anim2.end" dur="0.4s" fill="freeze"/>
<animateTransform id="anim2" attributeName="transform" attributeType="XML" type="rotate" from="30" to="0" begin="anim1.end" dur="0.4s" fill="freeze"/>
Stomatic answered 2/9, 2010 at 19:5 Comment(1)
Works in (oold) Firefox 10, doesn't work in (up-to-date) Chrome 32, just if anyone encounters the same issue. And some useful links describing all the capabilities of animation timing: W3C SVG 1.1 Spec., Developer.Mozilla.org.Confectioner
T
38

You can also just loop within a single animateTransform by providing a values attribute with a semi-colon separated list:

<animateTransform attributeName="transform" type="rotate"
     values="0;30;0" begin="0s" dur="0.8s" fill="freeze"
     repeatCount="indefinite" />

Here's an example (checked in Firefox 4.0 and Chrome).

Trengganu answered 22/12, 2010 at 11:43 Comment(2)
@janaspage I just stumbled across documentation for the values attribute here: w3.org/TR/smil-animation/#ValuesAttributePinniped
although this accomplishes the task, it doesn't actually sequence two animations; would be nice to know how to sequence animations and repeart them in SMILHowdy
W
9

it's also possible to add/subtract (milli)seconds:

  begin="anim2.end-500ms"
Whaleback answered 1/11, 2011 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.