XML technologies / SVG / Using animations / Ways to implement animations / animateMotion moves an element along a path

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

The tag <animateMotion> moves an element along a defined path. It has these attributes:

Note:
keyPoints, when used in the tag <animateMotion>, must contain x/y coordinate pairs. Lists take the form x1,y1;x2,y2;...;xn,yn: semicolons separate pairs and commas separate their values. The attributes from, to and by must also contain value pairs.

<defs>
  <animateMotion xlink:href="#Quadr1" dur="3s" path="M0 0 l+200 +200" fill="freeze" calcMode="discrete"/>
  <animateMotion xlink:href="#Quadr2" dur="6s" path="M0 0 l+200 +200" rotate="45"/>
  <animateMotion xlink:href="#Quadr3" dur="3s" path="M0 0 l+200 +200" repeatCount="10" repeatDur="12s"/>
</defs>
<g>
  <path id="Pfad" d="M0 0 l+200 +200" style="stroke:black;stroke-opacity:0.5;fill:none"/>
  <rect id="Quadr1" x="0" y="0" width="10" height="10" style="fill:red;stroke:black;"/>
</g>
<g transform="translate(0 50)">
  <path id="Pfad" d="M0 0 l+200 +200" style="stroke:black;stroke-opacity:0.5;fill:none"/>
  <rect id="Quadr2" x="0" y="0" width="10" height="10" style="fill:red;stroke:black;"/>
</g>
<g transform="translate(0 100)">
  <path id="Pfad" d="M0 0 l+200 +200" style="stroke:black;stroke-opacity:0.5;fill:none"/>
  <rect id="Quadr3" x="0" y="0" width="10" height="10" style="fill:red;stroke:black;"/>
</g>

Animations at runtime

Figure: Animations at runtime.

Note:
Still images rarely represent animations well, so try the animation yourself.

   

 

 

 

back to top