SVG 1.2 - 27 October 2004
The animation elements specifies an SVG document or an SVG document fragment which provided synchronized animated vector graphics. Like video, the animation element is a graphical object with size determined by its x, y, width and height attributes.
animation Schema
<define name='animation'> <element name='animation'> <ref name='attlist.animation'/> <ref name='SVG.animation.content'/> </element> </define> <define name='SVG.animation.content'> <zeroOrMore> <ref name='SVG.Description.class'/> </zeroOrMore> <zeroOrMore> <choice> <ref name='SVG.Animation.class'/> <ref name='SVG.Handler.class'/> </choice> </zeroOrMore> </define> <define name='attlist.animation' combine='interleave'> <ref name='SVG.Core.attrib'/> <ref name='SVG.Conditional.attrib'/> <ref name='SVG.Opacity.attrib'/> <ref name='SVG.Graphics.attrib'/> <ref name='SVG.Focusable.attrib'/> <ref name='SVG.Clip.attrib'/> <ref name='SVG.Mask.attrib'/> <ref name='SVG.Filter.attrib'/> <ref name='SVG.Compositing.attrib'/> <ref name='SVG.GraphicalEvents.attrib'/> <ref name='SVG.Tooltip.attrib'/> <ref name='SVG.Cursor.attrib'/> <ref name='SVG.XLinkEmbed.attrib'/> <ref name='SVG.External.attrib'/> <ref name='SVG.AnimationTiming.attrib'/> <ref name='SVG.Media.attrib'/> <ref name='SVG.Filter.attrib'/> <ref name='SVG.Compositing.attrib'/> <ref name='SVG.GraphicalEvents.attrib'/> <ref name='SVG.Tooltip.attrib'/> <ref name='SVG.Cursor.attrib'/> <ref name='SVG.XLinkEmbed.attrib'/> <ref name='SVG.External.attrib'/> <ref name='SVG.AnimationTiming.attrib'/> <ref name='SVG.Media.attrib'/> <ref name='SVG.BackgroundFill.attrib'/> <ref name='SVG.AnimationTimingNoMinMax.attrib'/> <ref name='SVG.AnimationSync.attrib'/> <optional> <attribute name='x' svg:animatable='true' svg:inheritable='false'> <ref name='Coordinate.datatype'/> </attribute> </optional> <optional> <attribute name='y' svg:animatable='true' svg:inheritable='false'> <ref name='Coordinate.datatype'/> </attribute> </optional> <attribute name='width' svg:animatable='true' svg:inheritable='false'> <ref name='Length.datatype'/> </attribute> <attribute name='height' svg:animatable='true' svg:inheritable='false'> <ref name='Length.datatype'/> </attribute> <optional> <attribute name='preserveAspectRatio' a:defaultValue='xMidYMid meet' svg:animatable='yes' svg:inheritable='false'> <ref name='PreserveAspectRatioSpec.datatype'/> </attribute> </optional> <ref name='SVG.transform.attrib'/> </define>
The usual SMIL animation features are used to start and stop the animation at the appropriate times. The xlink:href attribute refers to the vector graphics content that is to be animated.
In the case where the animation element references an external SVG document the same set of rules as used when referencing external SVG images apply.
In the case where the animation element references an SVG document fragment, the conceptual processing model is that the entire document containing the fragment is processed as a complete SVG document instance (coordinate systems transformations and stylesheets are applied; scripts are executed; etc.). The document is conceptually rendered to an invisible (offscreen) canvas except for the referenced fragment which is rendered directly to the screen canvas. When the animation element references a document fragment the preserveAspectRatio attribute has no meaning. The rules for applying x, y, width and height are the same set of rules that apply for the use element.
The following example illustrates the use of the animation element.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.2"> <defs> <rect id="movieClip" x="-50" y="-50" width="100" height="100" fill="purple" stroke="black"> <animate attributeName="fill" values="purple;yellow;purple" keyTimes="0;.5;1" begin="0" dur="2" fill="freeze"/> </rect> </defs> <animation begin="1" dur="3" repeatCount="1.5" fill="freeze" x="100 y="100" width="100" height="100" xlink:href="#movieClip"/> <animation begin="2" x="100" y="300" width="100" height="100" xlink:href="#movieClip"/> </svg>
The DOM interface for the animation element is shown below:
interface SVGAnimationElement: SVGMediaElement, SVGURIReference, SVGLangSpace, SVGStylable, SVGTransformable { readonly attribute SVGAnimatedLength x; readonly attribute SVGAnimatedLength y; readonly attribute SVGAnimatedLength width; readonly attribute SVGAnimatedLength height; readonly attribute SVGAnimatedPreserveAspectRatio preserveAspectRatio; };
There exist a number of usage scenarios for transition effects between views of SVG. For example, an image slideshow or multipage SVG documents.
SMIL 2.0 defines syntax for allowing the transition between multimedia elements to include a transition, such as a fadein/fadeout. There is a comprehensive set of transition effects defined by SMPTE and listed in an appendix of SMIL 2.0 Transition Effects
SVG 1.2 adds the transition effects from SMIL 2.0, in particular the transition element and the transIn and transOut attributes.
The transition element defines a single transition class. A transition element can be the child of any class, although normally they are defined within a defs section.
transition Schema
<define name='transition'> <element name='transition'> <ref name='attlist.transition'/> <ref name='SVG.transition.content'/> </element> </define> <define name='attlist.transition' combine='interleave'> <ref name='SVG.Core.attrib'/> <optional> <attribute name='dur'/> </optional> <optional> <attribute name='startProgress'> <data type='float'/> </attribute> </optional> <optional> <attribute name='endProgress'> <data type='float'/> </attribute> </optional> <optional> <attribute name='direction' a:defaultValue='forward'> <choice> <value>forward</value> <value>reverse</value> </choice> </attribute> </optional> <optional> <attribute name='fadeColor' a:defaultValue='black'/> </optional> <!-- refer to the full schema for the transition type attributes. --> <ref name='attlist.transition-types'/> </define> <define name='SVG.transition.content'> <zeroOrMore> <ref name='SVG.Description.class'/> </zeroOrMore> </define> <define name='SVG.Transition.attrib' combine='interleave'> <ref name='transIn.attrib'/> <ref name='transOut.attrib'/> </define> <define name='transIn.attrib'> <optional> <attribute name='transIn'/> </optional> </define> <define name='transOut.attrib'> <optional> <attribute name='transOut'/> </optional> </define>
Attributes:
None of the attributes on the transition element are animatable.
SVG 1.2 does not allow extensions to the transition types specified by SMIL 2.0.
Once a transition has been defined in a document, then an transition effect is applied by referencing the transition from the transIn and transOut attributes. The transition attributes are added to the elements that can undergo a transition (listed below).
Transitions specified with a transIn attribute will begin at the beginning of the animation's active duration. Transitions specified with a transOut attribute will end at the end of the animation's active duration or end at the end of the element's fill state if a non-default fill value is applied.
Note that in SVG, the transition effects only apply to animations modifying the xlink:href attribute of graphical elements: image, video, use, page and feImage.
The value of the attributes is a semicolon-separated list of transition element identifiers. The transition used is the first supported transition in the list.
Below is an example of a transition:
<svg width="100%" height="100%" version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <transition id="fadeToRed2s" type="fade" subtype="fadeToColor" fadeColor="red" dur="2s"/> <transition id="fadeFromRed1s" type="fade" subtype="fadeFromColor" fadeColor="red" dur="1s"/> </defs> <image x="0" y="0" width="100" height="100" transIn="fadeFromRed1s" transOut="fadeToRed2s"> <animate attributeType="XML" attributeName="xlink:href" begin="0s" dur="60s" values="1.jpg;2.jpg;3.jpg;4.jpg" fill="freeze"/> </image> </svg>
SVG supports media elements similar to the SMIL Media Elements. Media elementsdefine their own timelines within their time container. All SVG Media elements support the SVG Timing attributes and run time synchronization.
The following elements are media elements:
SVG supports a subset of SMIL 2.0's feature set for nested time containers. All time containers support all or some of the SVG Timing Attributes. The following elements in the SVG language define a new time container:
Time containers and timeAction are defined by the SMIL2.0 spec.
SVG supports the following attributes on time containers and media elements from SMIL 2.0 to control run-time synchronization of different time containers:
The normative definition for these attributes is the SMIL 2.0 specification.
SVG 1.2 adds the speed attribute from the SMIL 2.0 Timing Manipulations Module.
The speed attribute controls the local playback speed of an element, to speed up or slow down the effective rate of play relative to the parent time container. The speed attribute is supported on all timed elements. The argument value does not specify an absolute play speed, but rather is relative to the playback speed of the parent time container. The specified value cascades to all time descendants. Thus if a par and one of its children both specify a speed of 50%, the child will play at 25% of normal playback speed.
Values less than 0 are allowed, and cause the element to play backwards. An element can only play backwards if there is sufficient information about the simple and active durations. Specifically:
If the cascaded speed value for the element is negative and if either of the above two conditions is not met, the element will begin and immediately end (i.e. it will behave as though it had a specified active duration of 0).
In SVG 1.2, a document may contain multiple time containers, such as multiple pages or video elements. In order to pause a particular container or timed element, the ElementTimeControl interface has been extended.
interface ElementTimeControl { void beginElement(); void beginElementAt(in float offset); void endElement(); void endElementAt(in float offset); void pauseElement(); void unpauseElement(); readonly boolean elementPaused; }
The ElementTimeControl interface is added to all media elements and all time containers.
SVG 1.2 updates the definition of the accessKey syntax used to control the animation begin or end.
Describes an accessKey that determines the element begin. The element begin is defined relative to the time of the keydown event corresponding to the specified key. From a formal processing model perspective, accessKey is a keydown event listener on the document which behaves as if stopPropagation() and preventDefault() have both been invoked. The "character" value can be any of the keyboard event identifier strings listed in Appendix A.2 of the DOM3 Events specification.