XML technologies / SVG / Interactive graphics / Manipulating graphic elements / Starting animations with scripts

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

Animations too can easily start on a mouse click. Although JavaScript can control animations directly, defining an animation and starting it with a simple hyperlink is even easier. A variation of this chapter’s first example demonstrates this. An animation is added to the button that changes color on hover, shrinking the circle to a radius of one pixel. Set the attribute begin to indefinite. All other parameters must be defined so the animation works.

Note:
First test the animation by assigning the value 1s to the attribute begin. Only after verifying the animation itself can you be sure a later failure comes from its invocation or start.

To start the animation, an <a> tag is enough. Set its xlink:href attribute to the animation name defined by the id attribute of the <animate> tag.

<a xlink:href="#animieren" >
  <circle onmouseover="farbeAendern(evt)" onmouseout="farbeAendern(evt)" cx="100" cy="100" r="20" style="fill:red">
    <animate id="animieren" attributeName="r" begin="indefinite" from="20" to="1" by="-1" dur="5s" fill="freeze"/>
  </circle>
</a>

   

 

 

 

back to top