Animejs
Animejs
Animejs
js
Main features
Browser support
Usage
$ npm install animejs# OR
anime({
targets: 'div',
translateX: [
],
rotate: '1turn',
backgroundColor: '#FFF',
duration: 2000,
loop: true
});
API
Targets
The targets property defines the elements or JS Objects to animate.
Types Examples
NodeList document.querySelectorAll('.item')
Targets examples
Animatable properties
Types Examples
CSS
anime({
targets: 'div',
});
anime({
targets: 'div',
});
var myObject = {
prop1: 0,
prop2: '0%'
anime({
targets: myObject,
prop1: 50, // Animate the 'prop1' property from myObject to 50
});
DOM Attributes
<input value="0">
anime({
targets: input,
});
SVG Attributes
</svg>
anime({
targets: 'polygon',
});
Property parameters
See Easing
easing 'easeOutElastic' function
functions
number, boolean,
round false Power of 10
function
anime({
translateX: {
value: 250,
duration: 800
},
rotate: {
value: 360,
duration: 1800,
easing: 'easeInOutSine'
},
scale: {
value: 2,
duration: 1600,
delay: 800,
easing: 'easeInOutQuart'
},
});
anime({
targets: 'div',
translateX: 250,
rotate: 180,
duration: function(target) {
return target.getAttribute('data-duration');
},
},
});
Animation parameters
Parameters relative to the animation to specify the direction, the number of loops or
autoplay.
anime({
targets: 'div',
translateX: 100,
duration: 2000,
});
Property values
Single value
Values examples
anime({
targets: 'div',
duration: 1500
});
anime({
targets: 'div',
duration: 1500
});
anime({
targets: 'div',
translateX: function(el) {
return el.getAttribute('data-x');
},
translateY: function(el, i) {
},
scale: function(el, i, l) {
return (l - i) + .25;
},
});
Keyframes
Keyframes are defined using an Array of property Object.
Instance's duration is divided by the number of keyframes of each properties if not
specified.
anime({
targets: 'div',
translateX: [
],
translateY: [
],
scaleX: [
],
scaleY: [
});
Timeline
Basic timeline
direction: 'alternate',
loop: 3,
autoplay: false
});
myTimeline
.add({
targets: '.square',
translateX: 250
})
.add({
targets: '.circle',
translateX: 250
})
.add({
targets: '.triangle',
translateX: 250
});
Relative offset
myTimeline
.add({
targets: '.square',
translateX: 250
})
.add({
targets: '.circle',
translateX: 250,
})
.add({
targets: '.triangle',
translateX: 250,
});
Absolute offset
myTimeline
.add({
targets: '.square',
translateX: 250,
.add({
targets: '.circle',
translateX: 250,
})
.add({
targets: '.triangle',
translateX: 250,
});
Playback controls
Play, pause, restart, seek animations or timelines.
Play / Pause
targets: 'div',
translateX: 250,
direction: 'alternate',
loop: true,
Restart
targets: 'div',
translateX: 250,
direction: 'alternate',
loop: true,
autoplay: false
});
Restart example
Reverse
var reverseAnim = anime({
targets: 'div',
translateX: 250,
direction: 'alternate',
loop: true
});
Reverse example
Seek
targets: 'div',
translateX: 250,
elasticity: 200,
autoplay: false
});
Seek example
Callbacks
Execute a function at the beginning, during or when an animation or timeline is
completed.
animation
update function Called at time = 0
Object
animation
begin function Called after animation delay is over
Object
Callbacks examples
Update
translateX: 250,
delay: 1000,
update: function(anim) {
});
Update example
Begin
translateX: 250,
delay: 1000,
begin: function(anim) {
});
Check if the animation has begun with myAnimation.began, return true or false.
Begin example
Run
translateX: 250,
delay: 1000,
run: function(anim) {
console.log(anim.currentTime);
});
Run example
Complete
translateX: 250,
complete: function(anim) {
console.log(anim.completed);
});
Complete example
Promises
myAnimation.finished returns a Promise object which will resolve once the
animation has finished running.
Promises example
SVG
Motion path
});
Morphing
</svg>
});
Morphing example
Line drawing
Line drawing animation of an SVG shape:
anime({
strokeDashoffset: [anime.setDashoffset, 0]
});
Easing functions
The easing parameter can accept either a string or a custom Bzier curve coordinates
(array).
Built in functions
Penner's equations:
Usage:
anime({
targets: 'div',
translateX: 100,
});
anime({
targets: 'div',
translateX: 100,
easing: 'easeOutElastic',
});
Elasticity examples
targets: 'div',
translateX: 100,
easing: [.91,-0.54,.29,1.56]
});
// Usageanime({
targets: 'div',
translateX: 100,
easing: 'myCustomEasingName'
});
// Usageanime({
targets: 'div',
translateX: 100,
easing: 'myCustomCurve'
});
anime.running
anime.running;
anime.remove(target)
anime.getValue(target, property)
anime.path(pathEl)
anime.setDashoffset(pathEl)
anime({
});
anime.easings
anime.easings;
anime.timeline()
Timeline examples
anime.random(x, y)
====
Thanks to Animate Plus and Velocity that inspired anime.js API, BezierEasing and
jQuery UI for the easing system. Tim Branyen For the Promise implementation.