Jump to content
Wikipedia The Free Encyclopedia

SVG animation

From Wikipedia, the free encyclopedia
Open XML-based standard vector graphics format
This article has multiple issues. Please help improve it or discuss these issues on the talk page . (Learn how and when to remove these messages)
This article needs to be updated. Please help update this article to reflect recent events or newly available information. (February 2010)
This article's tone or style may not reflect the encyclopedic tone used on Wikipedia. See Wikipedia's guide to writing better articles for suggestions. (August 2014) (Learn how and when to remove this message)
(Learn how and when to remove this message)
Scalable Vector Graphics


Animation of Scalable Vector Graphics, an open XML-based standard vector graphics format is possible through various means:

Libraries have also been written as a shim to give current SVG-enabled browsers SMIL support.[9] This method is also known as SVG+Time.[citation needed ]

Because SVG supports PNG and JPEG raster images, it can be used to animate such images as an alternative to APNG and Multiple-image Network Graphics (MNG).

History

[edit ]

SVG animation elements were developed in collaboration with the working group that published several versions of Synchronized Multimedia Integration Language (SMIL). The SYMM Working Group (in collaboration with the SVG Working Group) developed the SMIL Animation specification, which represents a general-purpose XML animation feature set. SVG incorporates the animation features defined in the SMIL Animation specification and provides some SVG-specific extensions.

In June 1998, the "Synchronized Multimedia Working Group" (known as "SYMM"[10] ) within the World Wide Web Consortium ("W3C") published the first recommended version of the specification known as "SMIL 1.0".[11] [12] Shortly after the 1998 publication of SMIL 1.0, a group of companies led by Microsoft published "Timed Interactive Multimedia Extensions for HTML (HTML+TIME); Extending SMIL into the Web Browser".[13] For the next two years, the lead author of HTML+TIME (Patrick Schmitz) worked with the SYMM working group, while also working with the SVG working group. Shortly after the publication of SMIL 2.0, Schmitz and co-author Aaron Cohen (from Intel) published SMIL Animation on 4 September 2001.[14] [15] SVG 1.0 also became a W3C Recommendation on 4 September 2001.

Certain web browsers added support for SVG animation during the 2000s, including Amaya as early as 2003, but SVG animation was only supported by widely used browsers beginning in the 2010s, notably by Firefox 4 (2011). Internet Explorer supports ECMAScript animation, and its successor Microsoft Edge supports ECMAScript and CSS animations as of version 42.17134.

Examples

[edit ]
This section possibly contains original research . Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (May 2019) (Learn how and when to remove this message)

The following code snippets demonstrate three techniques to create animated SVG images on compatible browsers. The relevant parts are highlighted in yellow. Click the images' thumbnails to see their animated versions.

SVG animation using SMIL

[edit ]
See file SVG animation using SMIL.svg.
SVG animation using SMIL
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svgversion="1.1"xmlns="http://www.w3.org/2000/svg"xmlns:xlink="http://www.w3.org/1999/xlink"
width="100%"height="100%"viewBox="-4 -4 8 8">
<title>SVGanimationusingSMIL</title>
<circlecx="0"cy="1"r="2"stroke="red"fill="none">
<animateTransform
attributeName="transform"
attributeType="XML"
type="rotate"
from="0"
to="360"
dur="1s"
repeatCount="indefinite"/>
</circle>
</svg>

SVG animation using CSS

[edit ]
See file SVG animation using CSS.svg.
SVG animation using CSS
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svgversion="1.1"xmlns="http://www.w3.org/2000/svg"xmlns:xlink="http://www.w3.org/1999/xlink"
width="100%"height="100%"viewBox="-4 -4 8 8">
<title>SVGanimationusingCSS</title>
<style>
@keyframesrot_kf{
from{transform:rotate(0deg);}
to{transform:rotate(360deg);}
}
.rot{animation:rot_kf1slinearinfinite;}
</style>
<circleclass="rot"
cx="0"cy="1"r="2"stroke="blue"fill="none"/>
</svg>

SVG animation using ECMAScript

[edit ]
A drawing of a streetlight that can be interactive
A traffic light, animated using SVG animation and Javascript.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svgversion="1.1"xmlns="http://www.w3.org/2000/svg"xmlns:xlink="http://www.w3.org/1999/xlink"width="100%"height="100%"viewBox="-4 -4 8 8"onload="rotate(evt)">
<title>SVGanimationusingECMAScript</title>
<script>
functionrotate(evt){
constobject=evt.target.ownerDocument.getElementById('rot');
setInterval(()=>{
constnow=newDate();
constmilliseconds=now.getTime()%1000;
constdegrees=milliseconds*0.36;//360degreesin1000ms
object.setAttribute('transform',`rotate(${degrees})`);
},20);
}
</script>
<circleid="rot"
cx="0"cy="1"r="2"stroke="green"fill="none"/>
</svg>

Though the example above works, it is not the optimal implementation; the animation is limited to 50 frames per second (FPS). Using requestAnimationFrame provides better performance and can reach 60 FPS:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svgversion="1.1"xmlns="http://www.w3.org/2000/svg"xmlns:xlink="http://www.w3.org/1999/xlink"width="100%"height="100%"viewBox="-4 -4 8 8"onload="init()">
<title>SVGanimationusingrequestAnimationFrame()</title>
<script>
letobject;

functioninit(){
object=document.getElementById('rot');
window.requestAnimationFrame(rotate);
}

functionrotate(timestamp){
constmilliseconds=timestamp%1000;
constdegrees=milliseconds*0.36;//360degreesin1000ms
object.setAttribute('transform',`rotate(${degrees})`);
window.requestAnimationFrame(rotate);
}
</script>
<circleid="rot"cx="0"cy="1"r="2"stroke="green"fill="none"/>
</svg>

SMIL attributes to identify the target attribute

[edit ]

The following are the animation attribute which identify the target attribute for the given target element whose value changes over time. attributeName = "<attributeName>" specifies the name of the target attribute. An XMLNS prefix may be used to indicate the XML namespace for the attribute. The prefix will be interpreted in the scope of the current animation element.

attributeType = "CSS | XML | auto" specifies the namespace in which the target attribute and its associated values are defined. CSS specifies that the value of ‘attributeName’ is the name of a CSS property defined as animatable in this specification. XML specifies that the value of ‘attributeName’ is the name of an XML attribute defined in the default XML namespace for the target element. The attribute must be defined as animatable in this specification. auto The default value is 'auto'. The implementation should match the ‘attribute Name’ to an attribute for the target element. The implementation must first search through the list of CSS properties for a matching property name, and if none is found, search the default XML namespace for the element.

The MediaWiki wiki software automatically generates static, non-animated thumbnails of SVG images. Viewing the actual .svg image from each respective description page will show its animation in a compatible browser.

Libraries

[edit ]

There are several JavaScript libraries for working with SVG animation. An advantage to the use of such libraries is that these libraries often solve incompatibility issues in browsers through abstraction. Examples of libraries include Raphaël and Velocity.js

See also

[edit ]
Wikimedia Commons has media related to Animated SVG files .

References

[edit ]
  1. ^ "Scalable Vector Graphics (SVG) 1.1 Specification". World Wide Web Consortium. January 2003 – April 2009. Archived from the original on 27 August 2006. Retrieved 4 February 2010.
  2. ^ Festa, Paul (9 January 2003). "W3C releases scripting standard, caveat". CNet. Archived from the original on 17 May 2011. Retrieved 24 February 2010.
  3. ^ Bulterman, D.C.A.; Lloyd Rutledge (November 2008). SMIL 3.0: Interactive Multimedia for the Web, Mobile Devices and Daisy Talking Books. X.media.publishing (2nd ed.). New York: Springer. p. 508. ISBN 9783540785460. Archived from the original on 2022年04月24日. Retrieved 2022年04月24日.
  4. ^ Dick Bulterman. SMIL 3.0. Archived from the original on 2022年04月24日. Retrieved 2022年04月24日.
  5. ^ "SVG Animation support in Amaya". World Wide Web Consortium. 15 April 2003. Archived from the original on 11 September 2009. Retrieved 4 February 2010.
  6. ^ McCathieNevile, Charles (31 October 2006). "Animating Your SVG". Opera Developer Community. Opera Software. Archived from the original on 7 March 2010. Retrieved 24 February 2010.
  7. ^ "SVG animation with SMIL". 29 March 2011. Archived from the original on 30 April 2011. Retrieved 29 March 2011.
  8. ^ "When can I use SVG SMIL animation?". Archived from the original on 2011年03月22日. Retrieved 2011年03月29日.
  9. ^ Dahlström, Erik (August 2008). "Tricks of javascript, SVG and SMIL". Opera Software at "SVG Open" website. Archived from the original on 6 April 2009. Retrieved 24 February 2010.
  10. ^ "W3C Synchronized Multimedia Home page". www.w3.org. Archived from the original on 2022年04月17日. Retrieved 2022年03月20日.
  11. ^ Hoschka, Philipp, ed. (1998年06月15日). "Synchronized Multimedia Integration Language (SMIL) 1.0 Specification". W3C. SYMM Working Group. Archived from the original on 2021年03月30日. Retrieved 2021年04月09日.
  12. ^ Khudairi, Sally; Jacobs, Ian; Mitchell, Ned; Lloyd, Andrew; Matsubara, Yumiko (1998年06月15日). "Press Release: W3C Issues SMIL as a W3C Recommendation". W3C. Archived from the original on 2020年02月08日. Retrieved 2021年04月09日.
  13. ^ Schmitz, Patrick; Yu, Jin; Santangeli, Peter (1998年09月18日). "Timed Interactive Multimedia Extensions for HTML (HTML+TIME); Extending SMIL into the Web Browser". World Wide Web Consortium (w3.org). Archived from the original on 2022年01月20日. Retrieved 2022年03月20日.
  14. ^ "Synchronized Multimedia Integration Language (SMIL 2.0)". www.w3.org. 7 August 2001. Archived from the original on 2022年03月26日. Retrieved 2022年03月20日.
  15. ^ Schmitz, Patrick; Cohen, Aaron (4 September 2001). "SMIL Animation". www.w3.org. Archived from the original on 2022年06月14日. Retrieved 2022年03月20日.
Animation topics
By country
Industry
Works
Techniques
Traditional
Stop motion
Computer
2D
3D
Puppetry
Mechanical
Other methods
Variants
History
Related topics
Products,
standards
Recommendations
Notes
Working drafts
Guidelines
Initiative
Deprecated
Obsoleted
Groups,
organizations
Elected
Working
Community, business
Closed
Software
Browsers
Conferences

AltStyle によって変換されたページ (->オリジナル) /