How to use it
As I said, there are no dependencies here. You just need to include the script.
The library is also available via:
- Bower: bower install vivus
- NPM: npm install vivus
- SPM: spm install vivus
- jsDelivr CDN: //cdn.jsdelivr.net/vivus/0.2.1/vivus.min.js
- WebJars
// Inline SVG
new Vivus('my-svg-id', {type: 'delayed', duration: 200}, myCallback);
// Dynamic load
new Vivus('my-div-id', {type: 'delayed', duration: 200, file: 'link/to/my.svg'}, myCallback);
The Vivus constructor asks for 3 parameters :
- The ID (or object) of DOM element to interact with.
It can be an inline SVG or a wrapper element to append an object tag from the option file.
- Options object (described in the following)
- Callback to call at the end of the animation (optional)
The options object must respect the following structure :
- type string
- define what kind of animation will be used: delayed, async, oneByOne, scenario or scenario-sync
- duration integer
- animation duration, in frames
- start string
- define how to trigger the animation
inViewport once the SVG is in the viewport
manual give you the freedom to call play method to start
autostart make it start right now
- delay integer
- time between the drawing of first and last path, in frames (only for delayed animations)
- file string
- link to the SVG to animate. If set, Vivus will create an object tag and append it to the DOM element given to the constructor. Be careful, use the onReady callback before playing with the Vivus instance.
- onReady function
- function called when the instance is ready to play
- dashGap integer
- whitespace extra margin between dashes. The default value is 2. Increase it in case of glitches at the initial state of the animation
- pathTimingFunction function
- timing animation function for each path element of the SVG. The function must accept a value between 0 and 1, then return a number between 0 and 1.
- animTimingFunction function
- timing animation function for the complete SVG. The function must accept a value between 0 and 1, then return a number between 0 and 1.
- forceRender boolean
- force the browser to re-render all updated path items. By default, the value is true on IE only. (more details)
- selfDestroy boolean
- remove all extra styling on the SVG, and leave it as original
To control the animation, there are three methods are available : play, stop and reset. The method play takes one parameter which is the speed. This value can be positive, negative (to go backwards), or under 1 to play slowly. By default the value is 1.