The <animateTransform> element performs
transformations over a period of time. Remember, these transformations
affect the overall coordinate system, so simply scaling
a rectangle will also result in the object's position changing.
SVG includes five types of transforms (translate, scale,
rotate, skewX, skewY) that can be performed.
Code Example
SVG Image
<?xml version="1.0"
standalone="no"?>
Right-click
on the image to open the SVG viewer pop-up menu. Click
'view SVG' to display the image in a new, full window
to zoom & pan the image.
(SVG Viewer Tips)
<!DOCTYPE svg PUBLIC "-//W3C//DTD
SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
width="500" height="500" >
<!--
Scaling a text element -->
<text x="5" y="15" style="font-size:
4pt;fill:blue;"> SVG is Fun !
<animateTransform attributeName="transform"
type="scale" from="1" to="5"
begin="0" dur="4s" fill="freeze"/>
</text>
In the first example, the <animateTransform>
element is used to set the transform animation properties
for the <text> element.The type of
transform is scale, by increasing from 1
to 5, so the text ends up being five times bigger.
We use the begin attribute which tells the
SVG viewer when to begin the animation. The dur
attribute implies that it will take 4 seconds to complete
the scaling. Finally, the text retains at the enlarged
size.
in the second example, the <animateTransform>
tag is used to set the transform animation properties
for the <rect> element. The type of
transform is rotate, and the from
and to attributes are used to specify that
the element will rotate from an angle of 0 degrees
to 360 degrees. The other two parameters in the from
and to attributes, namely the two 80,180
values, represent the coordinates for the rotation
point for the animation. The animation duration is
set to five seconds for a full rotation. Finally,
the repeat count is set to repeat indefinitely.
Right-click
on the image to open the SVG viewer pop-up menu. Click
'view SVG' to display the image in a new, full window
to zoom & pan the image.
(SVG Viewer Tips)
Code explanation
We can also combine multiple transformation
animations in the same element. The above example
includes the scale, rotate and translate
transformations. So the scaling, rotation and translation
of the duck are animated. First, the size of the duck
is reduced from 0.4 to 0.3. Second, the duck is rotated
from 0 degree to 21 degrees, and finally it moves
download to position (90,45) on the coordinate system.
Note that only a single transformation can be animated
per element so as to achieve this compound effect.
The <path> element is enclosed within
two grouping elements and one transformation animation
is applied to each.