Animate
A plugin for Reveal.js allowing to add animations using SVG.js.
Setup
To use the plugin include
<!-- Load content plugin --> |
to the header of your presentation and configure reveal.js and the plugin by
Reveal.initialize({ |
By default animations only play when using the Auto-Slide feature or when playing (or recording) an Audio-Slideshow. In order to always play an animation when moving to a slide, the plugin can be configured by setting the autoplay parameter to true.
The loadcontent plugin is only required when svg are loaded from an external file using the data-load="..." attributes (see examples below). It is important that RevealLoadContent is listed before RevealAnimate.
Usage
An animation can be included in a slide by adding an element with the data-animate attribute. If the loadcontent plugin is used, the filename of an SVG to be loaded can be provided by an attribute data-load="drawing.svg". Alternatively, an svg element can be manually placed within the element. The animation is provided by a comment with a JSON-string as follows:
<div data-animate data-load="drawing.svg"> |
The setup object is used to manipulate the SVG after loading. The animation object is used to create an SVG animation. Both objects are optional and specified by an array including individual changes to the SVG. Each item in the array has the following properties:
-
element(optional): The selector for any element(s) within the SVG on which themodifieris executed with the givenparameters. If multiple elements match the selector, the modifier is executed in a sequential fashion to all elements matched. If noelementis provided, themodifieris executed on the SVG element. -
modifier: Any function that can be used to manipulate SVG elements. Within thesetupobject, the modifier can be any user defined function manipulating the selected elements. Within theanimationobject, no user defined functions are allowed. -
parameters: An array of parameters for the chosenmodifier.
For animation items the parameters duration, delay, and when for the animate() function may be provided. If they are not provided the defaults are taken according to the documentation of SVG.js.
If a slide has fragments, the animation object can be provided as an array of an array. The first item of the array is an array of animations applied to the main slide, the following items are arrays of animations applied to the fragments.
The animate plugin is designed to work with the audio-slideshow plugin such that the timeline of the audio is synched with the timeline of the animation and that the animation is controlled with the audio controls. Alternatively, the animations can be controlled via the functions play(), pause(), and seek(timstamp).
Examples
The demo includes various animations showcasing different ways of using the plugin. Please have a look at the the source code.
Example: Heartbeat
The following example loads a heart and creates a heartbeat animation.
<div data-animate data-load="animate/heart.svg"> |
Example: Fragments
The following example loads a SVG file and makes selected elements of the svg appear as fragments.
<span class="fragment"></span> |
Example: Adding SVG elements
The following example loads a SVG file and adds additional SVG elements to it upon loading. When advancing through the fragments, these elements are shown.
<span class="fragment"></span> |
Example: Sequential animations
The following example loads an SVG file, clones elements of the SVG, and manipulates them. Then, the cloned elements are displayed sequentially.
<div data-animate data-load="animate/integer_program.svg"> |
License
MIT licensed
Copyright © 2023 Asvin Goel