animate() function creates individual animation instances that can target DOM elements, SVG elements, or JavaScript objects.
Creating Animations
Theanimate() function accepts two parameters: targets and animation parameters.
Animation Parameters
Duration and Timing
The animation duration in milliseconds.
Delay before the animation starts. Can be a function for per-target delays.
The easing function to control animation acceleration.
Playback Control
Number of loops or
true for infinite looping. Use -1 for infinite.If true, animation alternates direction on each loop.
Whether the animation starts automatically.
Animation Methods
All animations return an instance with control methods:play()
Starts or resumes the animation.pause()
Pauses the animation at its current position.restart()
Restarts the animation from the beginning.reverse()
Reverses the animation playback direction.seek(time)
Seeks to a specific time in milliseconds.Animating Canvas Objects
Anime.js can animate JavaScript objects, making it perfect for canvas animations:Callbacks
Called on each animation frame with the animation instance.
Called when the animation completes.
Called when the animation begins.
Called on each render frame.
Composition
Control how animations compose with existing animations on the same property:'replace'- Replaces the current animation'blend'- Additively blends with existing animations'none'- No composition (faster for many targets)
Promises
Animations return promises that resolve when complete:Advanced: Modifiers
A function to modify the animated value before it’s applied.
API Reference
animate(targets, parameters)
Creates and returns a new animation instance. Parameters:targets(string | Element | Object | Array) - The elements or objects to animateparameters(Object) - Animation configuration object
JSAnimation - Animation instance with control methods
Animations automatically initialize and play unless
autoplay: false is specified.