Anime.js

4.3.6 · active · verified Sun Apr 19

Anime.js is a fast, multipurpose, and lightweight JavaScript animation engine designed for the web. It allows developers to animate CSS properties, SVG, DOM attributes, and JavaScript objects with a simple yet powerful API. The current stable version is 4.3.6, with frequent patch releases addressing bug fixes and minor improvements, alongside feature releases introducing new capabilities like Auto Layout. Its key differentiators include its small footprint, versatility across different animation targets, and an intuitive API that simplifies complex animation sequences and timelines, making it suitable for both simple and advanced motion designs.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic CSS property animation, sequencing with timelines, and using the `createLayout` function to animate layout changes on DOM elements.

import anime, { createLayout } from 'animejs';

// Create a basic HTML structure for demonstration
document.body.innerHTML = `
  <style>
    .box { width: 100px; height: 100px; background-color: #3f51b5; margin: 10px; border-radius: 8px; }
    .container { display: flex; flex-direction: column; align-items: flex-start; }
  </style>
  <div class="container">
    <div id="box1" class="box"></div>
    <div id="box2" class="box"></div>
  </div>
`;

const box1 = document.getElementById('box1');
const box2 = document.getElementById('box2');

// Basic animation on a single element
anime({
  targets: box1,
  translateX: 270,
  rotate: '1turn',
  backgroundColor: '#ff4081',
  duration: 1200,
  easing: 'easeInOutQuad',
  loop: true,
  direction: 'alternate'
});

// Animation using a timeline for sequential effects
const tl = anime.timeline({
  easing: 'easeOutExpo',
  duration: 750,
  loop: true,
  delay: anime.stagger(100) // Delay between each box in the timeline
});

tl.add({
  targets: box2,
  scale: [0.8, 1.2],
  opacity: [0, 1]
})
.add({
  targets: box2,
  translateY: 50,
  backgroundColor: '#4caf50'
}, '-=250'); // Start this animation 250ms before the previous one ends

// Example of AutoLayout (requires multiple elements in a container to show changes)
const layoutAnim = createLayout({
  targets: '.container .box',
  easing: 'easeOutElastic(1, .8)',
  duration: 1000
});

// You would trigger layoutAnim.animate() on a state change that affects layout
// For demonstration, let's just animate an arbitrary property to see layout changes
const toggleLayout = () => {
  if (box1 && box2) {
    const newFlexDirection = box1.style.order === '1' ? 'column' : 'row';
    box1.style.order = box1.style.order === '1' ? '0' : '1';
    layoutAnim.animate({
      targets: '.container',
      flexDirection: newFlexDirection,
      opacity: 0.9,
      update: layoutAnim.onLayoutUpdate // Keep layout in sync during animation
    });
  }
};

setTimeout(toggleLayout, 5000); // Trigger a layout change after 5 seconds

view raw JSON →