SVG animation

Last updated

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

Contents

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 Portable Network Graphics (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

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

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

SVG animation using SMIL.svg
<?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"><animateTransformattributeName="transform"attributeType="XML"type="rotate"from="0"to="360"dur="1s"repeatCount="indefinite"/></circle></svg>

SVG animation using CSS

SVG animation using CSS.svg
<?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

A traffic light, animated using SVG animation and Javascript. Ampel.svg
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

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

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

Related Research Articles

A document type definition (DTD) is a specification file that contains set of markup declarations that define a document type for an SGML-family markup language. The DTD specification file can be used to validate documents.

Scalable Vector Graphics (SVG) is an XML-based vector image format for defining two-dimensional graphics, having support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium since 1999.

<span class="mw-page-title-main">Synchronized Multimedia Integration Language</span> XML-based markup language for multimedia presentations

Synchronized Multimedia Integration Language ) is a World Wide Web Consortium recommended Extensible Markup Language (XML) markup language to describe multimedia presentations. It defines markup for timing, layout, animations, visual transitions, and media embedding, among other things. SMIL allows presenting media items such as text, images, video, audio, links to other SMIL presentations, and files from multiple web servers. SMIL markup is written in XML, and has similarities to HTML.

XSLT is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG. Support for JSON and plain-text transformation was added in later updates to the XSLT 1.0 specification.

Mathematical Markup Language (MathML) is a mathematical markup language, an application of XML for describing mathematical notations and capturing both its structure and content, and is one of a number of mathematical markup languages. Its aim is to natively integrate mathematical formulae into World Wide Web pages and other documents. It is part of HTML5 and standardised by ISO/IEC since 2015.

X3D is a set of royalty-free ISO/IEC standards for declaratively representing 3D computer graphics. X3D includes multiple graphics file formats, programming-language API definitions, and run-time specifications for both delivery and integration of interactive network-capable 3D data. X3D version 4.0 has been approved by Web3D Consortium, and is under final review by ISO/IEC as a revised International Standard (IS).

Vector Markup Language (VML) is an obsolete XML-based file format for two-dimensional vector graphics. It was specified in Part 4 of the Office Open XML standards ISO/IEC 29500 and ECMA-376. According to the specification, VML is a deprecated format included in Office Open XML for legacy reasons only.

XML Linking Language, or XLink, is an XML markup language and W3C specification that provides methods for creating internal and external links within XML documents, and associating metadata with those links.

Catalogue Service for the Web (CSW), sometimes seen as Catalogue Service - Web, is a standard for exposing a catalogue of geospatial records in XML on the Internet. The catalogue is made up of records that describe geospatial data, geospatial services, and related resources.

In computer science and web development, XML Events is a W3C standard for handling events that occur in an XML document. These events are typically caused by users interacting with the web page using a device, such as a web browser on a personal computer or mobile phone.

<span class="mw-page-title-main">HTML5</span> Fifth and previous version of HyperText Markup Language

HTML5 is a markup language used for structuring and presenting hypertext documents on the World Wide Web. It was the fifth and final major HTML version that is now a retired World Wide Web Consortium (W3C) recommendation. The current specification is known as the HTML Living Standard. It is maintained by the Web Hypertext Application Technology Working Group (WHATWG), a consortium of the major browser vendors.

The Pronunciation Lexicon Specification (PLS) is a W3C Recommendation, which is designed to enable interoperable specification of pronunciation information for both speech recognition and speech synthesis engines within voice browsing applications. The language is intended to be easy to use by developers while supporting the accurate specification of pronunciation information for international use.

Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages which mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.

<span class="mw-page-title-main">EPUB</span> E-book format

EPUB is an e-book file format that uses the ".epub" file extension. The term is short for electronic publication and is sometimes stylized as ePUB. EPUB is supported by many e-readers, and compatible software is available for most smartphones, tablets, and computers. EPUB is a technical standard published by the International Digital Publishing Forum (IDPF). It became an official standard of the IDPF in September 2007, superseding the older Open eBook (OEB) standard.

<span class="mw-page-title-main">CSS animations</span> CSS3 properties that would let some HTML elements animate

CSS animations is a proposed module for Cascading Style Sheets that allows the animation of HTML document elements using CSS.

SMIL Timesheets is a style sheet language which is intended for use as an external timing stylesheet for the Synchronized Multimedia Integration Language (SMIL), and is meant to separate the timing and presentation from the content inside the markup of another language.

XHTML+RDFa is an extended version of the XHTML markup language for supporting RDF through a collection of attributes and processing rules in the form of well-formed XML documents. XHTML+RDFa is one of the techniques used to develop Semantic Web content by embedding rich semantic markup. Version 1.1 of the language is a superset of XHTML 1.1, integrating the attributes according to RDFa Core 1.1. In other words, it is an RDFa support through XHTML Modularization.

The Web platform is a collection of technologies developed as open standards by the World Wide Web Consortium and other standardization bodies such as the Web Hypertext Application Technology Working Group, the Unicode Consortium, the Internet Engineering Task Force, and Ecma International. It is the umbrella term introduced by the World Wide Web Consortium, and in 2011 it was defined as "a platform for innovation, consolidation and cost efficiencies" by W3C CEO Jeff Jaffe. Being built on The evergreen Web has allowed for the addition of new capabilities while addressing security and privacy risks. Additionally, developers are enabled to build interoperable content on a cohesive platform.

Multimodal Architecture and Interfaces is an open standard developed by the World Wide Web Consortium since 2005. It was published as a Recommendation of the W3C on October 25, 2012. The document is a technical report specifying a multimodal system architecture and its generic interfaces to facilitate integration and multimodal interaction management in a computer system. It has been developed by the W3C's Multimodal Interaction Working Group.

References

  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.