Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
194
rated 0 times [  199] [ 5]  / answers: 1 / hits: 42166  / 13 Years ago, sat, december 10, 2011, 12:00:00

how do I trigger an svg animate element to begin animating via javascript with an arbitrary event ? I'm imagining something like begin=mySpecialEvent, then later I can send mySpecialEvent and the animation will start (or start again if it has already played).


More From » events

 Answers
18

Here's an article that covers what you need:

http://dev.opera.com/articles/view/advanced-svg-animation-techniques/



Edit: link is removed. Archived copies:





In short:




  1. Create the <animation> with begin=indefinite so that it won't treat the animation as starting on document load. You can do this either via JavaScript or raw SVG source.


  2. Call beginElement() on the SVGAnimationElement instance (the <animate> element) when you're ready for the animation to start. For your use case, use a standard addEventListener() callback to invoke this method when you're ready, e.g.



    myAnimationElement.addEventListener('mySpecialEvent',function(){
    myAnimationElement.beginElement();
    },false);


[#88629] Thursday, December 8, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leifw

Total Points: 88
Total Questions: 103
Total Answers: 103

Location: France
Member since Thu, May 6, 2021
3 Years ago
;