You can use it for subtle UI flourishes, complex SVG morphing, intricate sequence choreography via its timeline, or even synchronizing animations to scroll position.
animate, timeline, stagger, etc.) to keep bundle size down.translateX, rotate, scale) without conflicts. Function-based values add dynamic control.stroke-dashoffset tricks made easy), and motion path animations.Scope API to adjust animations based on media queries.You have several options for adding Anime.js to your project:
Using NPM:
npm install animejs
Then import Anime.js methods as ES6 modules:
import { animate } from 'animejs'; Using a CDN:
ES6 Modules:
<script type="module">
import { animate } from 'https://cdn.jsdelivr.net/npm/animejs@VERSION/+esm';
</script> Global object:
<script src="https://cdn.jsdelivr.net/npm/animejs@VERSION/lib/anime.iife.min.js"></script>
<script>
const { animate } = anime;
</script> Local file:
ES6 Modules:
<script type="module">
import { animate } from './path/to/anime.esm.min.js';
</script> UMD Modules:
<script type="module">
import { animate } from './path/to/anime.esm.min.js';
</script> Global object:
<script src="path/to/anime.iife.min.js"></script>
<script>
const { animate } = anime;
</script> 1. Creating animations with Anime.js starts with the animate() method. This function accepts a target (CSS selector, DOM element, JavaScript object, or array of targets) and an options object that defines the animation:
const animation = animate('.element', {
translateX: 100,
scale: 2,
opacity: .5,
// start and end values
x: '6rem',
y: $el => $el.dataset.y,
// OR
x: {
to: 100,
delay: 0,
ease: 'inOut(4)'
},
// Keyframes
x: [0, 100, 200],
y: [0, 100, 200],
// OR
keyframes: [
{ x: 100, y: 100 },
{ x: 200, y: 200 },
],
// OR
keyframes: {
'0%' : { x: 0, y: 0 },
'50%' : { x: 100, y: 100 },
'100%': { x: 200, y: 200 },
},
duration: 400,
delay: 250,
ease: 'out(3)',
loop: 3,
alternate: true,
autoplay: false,
// Callbacks
onBegin: () => {},
onLoop: () => {},
onUpdate: () => {},
}); 2. API methods.
animation.play() animation.reverse() animation.pause() animation.restart() animation.alternate() animation.resume() animation.complete() animation.cancel() animation.revert() animation.seek() animation.stretch() animation.refresh()
3. Properties.
id: Gets or sets a unique identifier (String or Number) for the animation instance.targets: Gets an array containing the element(s) or object(s) being animated.currentTime: Gets or sets the animation’s overall current time position in milliseconds.iterationCurrentTime: Gets or sets the current time position within the current loop iteration in milliseconds.deltaTime: Gets the time elapsed (in ms) between the last frame and the current frame. Useful within onUpdate.progress: Gets or sets the overall animation progress as a value between 0 (start) and 1 (end).iterationProgress: Gets or sets the progress within the current loop iteration as a value between 0 and 1.currentIteration: Gets or sets the current loop iteration count (starting from 1).duration: Gets the total calculated duration of the animation in milliseconds (including delays, iterations).speed: Gets or sets the playback speed multiplier (e.g., 1 is normal, 2 is double speed, 0.5 is half speed).fps: Gets or sets the target frames per second for the animation calculation.paused: Gets or sets the paused state of the animation (Boolean).began: Gets or sets whether the animation has started playing at least once (Boolean).completed: Gets or sets whether the animation has reached its end state (Boolean).reversed: Gets or sets whether the animation’s direction is currently reversed (Boolean).Anime.js 4.0 uses a modular architecture that allows you to import only what you need. Check out the Official Documentation for more details.
requestAnimationFrame-synchronized alternative to setTimeout or setInterval. You schedule function callbacks to run at specific times or intervals, perfectly synced with the main Anime.js animation loop (driven by the Engine). This is crucial when you need actions (like adding/removing classes, updating non-animatable properties, or triggering external logic) to happen at precise moments relative to your animations, avoiding timing mismatches you might get with standard browser timers.onComplete callbacks (which can become brittle), you create a timeline instance and .add() animation definitions or Timer callbacks to it. The timeline manages the overall sequence, allowing you to define precise start times, overlaps, and gaps between different animation parts. It treats the entire sequence as a single controllable unit with its own play, pause, seek, reverse, etc. methods. Essential for anything beyond simple, isolated tweens.animate() is great for defining set-and-forget animations, Animatable is optimized for situations where property values change very frequently based on external factors – think tracking mouse cursor movement, reacting to real-time data, or driving animations within a requestAnimationFrame loop you manage yourself. It’s designed for high-performance, continuous updates by efficiently setting target properties without the overhead of creating a full new animation instance each time. Consider it a more direct, performant way to apply interpolated values when the source of those values is constantly changing.onDragStart, onDrag, onDragEnd, onThrow, etc.) and methods to programmatically control the draggable state. It’s a self-contained solution for adding drag-and-drop UI features.IntersectionObserver or scroll event listeners and calculating progress, ScrollObserver lets you define trigger elements and link them to Anime.js Animation, Timeline, or Timer instances. You can configure various synchronization modes (e.g., play animation when element enters view, scrub through timeline based on scroll progress within a section) and define precise trigger points (thresholds). It simplifies creating scroll-driven narratives or reveal effects.Scope is designed for component-based architectures (React, Vue, Svelte, Web Components) and responsive design. You create a scope, often tied to a specific component’s root element. Animations defined within that scope can: stagger() provides helper functions to generate delays or even property values that increment progressively based on index, position, or other factors. It supports different distribution patterns (e.g., linear, from center, from edges, random) and can stagger time delays or the actual animated values themselves. Great for visually appealing entrance/exit animations on collections of items.d attribute of <path> elements, allowing smooth transitions between different shapes (requires compatible path data).stroke-dashoffset and stroke-dasharray attributes to create the effect of lines being drawn or erased.<path>. You define the path, and Anime.js handles animating the element’s transform properties (translateX, translateY, rotate) to follow it.requestAnimationFrame loop. It manages the timing, updates, and synchronization of all active Animation, Timer, and Timeline instances. You typically don’t interact with the Engine directly, but understanding its role helps grasp how everything stays in sync.v4.0.2 (04/24/2025)
v4.0.1 (04/09/2025)
v4.0.0 (04/06/2025)
v3.2.0 (04/28/2020)
v3.1.0 (07/27/2019)
v3.0.1 (01/17/2019)
01/12/2019
06/18/2018
The post Lightweight & Versatile JavaScript Animation Engine – Anime.js appeared first on CSS Script.
Far in the distant future, long after the human race has spread itself among the…
The cybersecurity landscape in 2026 is defined by unprecedented sophistication. Threat actors are leveraging generative…
Have you noticed? You can’t spell ‘Edward Kenway’ without ‘wayward’. And the protagonist of Assassin’s…
Hands Over is a new multiplayer horror party game that takes some of your favorite…
Have you noticed? You can’t spell ‘Edward Kenway’ without ‘wayward’. And the protagonist of Assassin’s…
Have you noticed? You can’t spell ‘Edward Kenway’ without ‘wayward’. And the protagonist of Assassin’s…
This website uses cookies.