Global Navigation
Support Resources
Hand Coding Content in SVG - Tips
- Animating colors and visibility
- Targets
- Timing
- Key Frames
- The begin attribute
- RepeatCount
- Creating a flipbook of images
1. Animating colors and visibility
To animate colors, use code similar to the following:
-
<animate attributeName="fill" dur="1.5"
repeatCount="indefinite" keyTimes="0;0.5;1"
values="lemonchiffon;peachpuff;lemonchiffon" />
To animate visibility, use code similar to the following:
-
<animate attributeName="visibility" dur="5"
repeatCount="indefinite" keyTimes="0;0.5;1"
values="visible;hidden;visible" />
2. Targets
To specify the target of an animate element:
Use either the xlink:href attribute OR target the parent.
To target the parent, add the animate node as a child of the node you wish to animate.Remember when using the xlink:href attribute, preface the target id with a "#" (number sign). You can target the following attributeName's: width, height, x, visibility, fill, stroke (although fill and stroke are treated the same).
Category Top3. Timing
Timing is critical for animations to work correctly. You must specify the dur attribute, which indicates how long the animation runs. If you do not specify the units, the default is seconds. You can also use the suffix "ms" to indicate milliseconds. You can also specify keyTimes, which is important when you use about key frames.
Category Top4. Key Frames
Specify the values that you're animating over. You can use any of the following options:
Explicit values:
-
<animate attributeName="height" dur="1"
keyTimes="0;0.5;1" values="30;25;30"/>
Note: the values list has the same number of items as the keyTimes list. (there should be the same number of values as there are keyTimes). As well, please note the keyTimes attribute lists values from 0 to 1 (inclusive).
The keyTimes array in conjunction with the duration attribute indicates when to hit each value.
Example: From/To/By:
-
<animate attributeName="height" dur="1"
keyTimes="0;0.25;0.5;0.75;1" from="20" to="40" by="5"/>
In the previous example, the from and to attributes are equivalent to values="20;25;30;35;40".Note also that the number of values is still equal to the number of keyTimes.
Example: From/To:
-
<animate attributeName="height" dur="1" from="20" to="40"/>
In the previous example, the from and to attributes are equivalent to values="20,40". Note also that the keyTimes array is optional (if it were present, it would be keyTimes="0;1").
For non-integral attributes (for example, visibility, fill or stroke) only explicit values are supported. For example:
-
<animate attributeName="visibility" dur="1"
values="visible;hidden"/>
5. The begin attribute
The begin attribute is a very powerful attribute. It enables animations to be synchronized based on time, or based on each other. The following are acceptable values for the begin attribute: a number (indicating a number of seconds to wait); the word "indefinite" (indicating that the animation will be queued by a user action); or "<foo>.end" where <foo> is the name of some other animation.
Category Top5a. The begin attribute restriction
The SVG Transcoding Utility places a restriction on the way the "begin" attribute of <animate> is used. The restriction is that if the attribute refers to another animation (by id), that animation must occur earlier in the file.
-
<!-- This is supported -->
<animate id="foo" ...stuff deleted..../>
<animate id="bar" begin="foo.end" .... stuff deleted.../>
<!-- This is not supported -->
<animate id="bad" begin="definedLater.end" ..../>
<animate id="definedLater" ... />
6. RepeatCount
Any animation can repeat itself one or more times. It can also repeat forever, if you specify repeatCount="indefinite"
Category Top7. Creating a flipbook of images
One method for creating a flipbook is to use sprites. Sprites are created by first creating a group of images. If the visibility of the images is changed from hidden to visible to hidden again in quick succession, the images will appear to be animating.
For example:
-
<image xlink:href="images/ship00.gif" width="52" height="23">
-
<animate attributeName="visibility" begin="1s" dur="1"
keyTimes="0;0.1;1" values="visible;hidden;hidden"
fill="freeze"/>
<image xlink:href="images/ship01.gif" width="52" height="23">
-
<animate attributeName="visibility" begin="1s"
dur="1" keyTimes="0;0.1;0.2;1"
values="hidden;visible;hidden;hidden" fill="freeze"/>
<image xlink:href="images/ship02.gif" width="52" height="23">
-
<animate attributeName="visibility" begin="1s"
dur="1" keyTimes="0;0.2;0.3;1"
values="hidden;visible;hidden;hidden" fill="freeze"/>
Alternatively, you can use the switchGroup element.
Category Top