javascript - Embed animated SVG in HTML page, paused (without starting animation) -


you can embed svg file into (x)html 5 document:

<object data="anim.svg" id="svganim"/> 

or

<img src="anim.svg" alt="embedded svg"/> 

but if anim.svg animated, animation start playing page loads.

how can embed animated svg file such animation starts out paused? user can play animation pressing button (using unpauseanimations() in javascript)

an inelegant way

window.onload = function() { var svg_anim = document.getelementbyid('svganim').contentdocument.rootelement; svg_anim.pauseanimations(); }; 

disadvantage: doesn't work if embedded svg in different security context parent document. there better way?

one way solve make animations not start automatically changing svg file (to add begin="indefinite" animations start automatically). these animations can triggered call beginelement() animation elements want trigger. if have many such elements, it's easier use pauseanimations().

however, <img> elements can't start animations since no events ever fed svg itself, that's not going work there. , scripting disabled in case too, can't trigger or prevent animations way either.

with <object>, <embed> or <iframe> can scripting, e.g suggestion. can add script tag 1 of first children of svg root element of svg file , in <script> element call pauseanimations. can main document suggested.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -