Skip to content

@tank/animejs-mastery

1.0.0

Anime.js v4 mastery: animate(), createTimeline(), onScroll(), createDraggable(), createLayout(), SVG morphTo/createDrawable/motionPath, splitText(), stagger(), spring, WAAPI, createScope(). Production recipes included. Triggers: anime.js, animejs, createTimeline, stagger, spring animation, SVG morphing, scroll animation, onScroll, splitText, draggable, FLIP animation, hero animation, page transition, scroll reveal, micro-interaction, WAAPI, keyframes, easing, motion path.


name: animejs-mastery description: | Anime.js v4 animation expert for building stunning web animations. Covers the complete API: animate(), createTimeline(), createScope(), onScroll(), createDraggable(), createLayout(), createAnimatable(), SVG utilities (morphTo, createDrawable, createMotionPath), splitText(), stagger(), spring physics, WAAPI integration, and production-ready website animation recipes. Synthesizes official Anime.js v4 documentation and production animation patterns.

Trigger phrases: "anime.js", "animejs", "animate()", "createTimeline", "stagger", "spring animation", "SVG morphing", "SVG line drawing", "scroll animation", "onScroll", "text animation", "splitText", "draggable", "layout animation", "FLIP animation", "web animation", "hero animation", "page transition", "scroll reveal", "micro-interaction", "WAAPI", "keyframes", "easing function", "motion path"

Anime.js v4 Animation Mastery

Expert-level guidance for creating production-quality web animations using Anime.js v4, the lightweight JavaScript animation engine.

Core Principles

  1. Animate transforms and opacity first — compositor-friendly properties (translate, scale, rotate, opacity) run on GPU. Avoid animating layout properties (width, height, top, left) unless using createLayout().
  2. Use WAAPI for simple, JS for complexwaapi.animate() is 3KB and hardware-accelerated. Use full animate() (10KB) for JS objects, SVG attributes, function-based values, and advanced features.
  3. Always clean up — Call scope.revert() in SPA teardown, animation.revert() on removal. Memory leaks from orphaned animations are the #1 bug.
  4. Stagger everything — Single-element animations look flat. stagger() with easing transforms any list into a choreographed sequence.
  5. Spring > easing for interactionsspring({ bounce: 0.5 }) feels more natural than cubic beziers for user-triggered animations.

Quick-Start Recipes

"Animate elements on page load"

import { animate, stagger } from 'animejs';

animate('.card', {
  opacity: [0, 1],
  y: [20, 0],
  delay: stagger(100),
  ease: 'out(3)',
  duration: 600
});

"Create a sequenced timeline"

import { createTimeline } from 'animejs';

const tl = createTimeline({ defaults: { duration: 600, ease: 'out(3)' } });
tl.add('h1', { opacity: [0, 1], y: [30, 0] })
  .add('p', { opacity: [0, 1], y: [20, 0] }, '-=400')
  .add('.cta', { opacity: [0, 1], scale: [0.9, 1] }, '-=300');

"Trigger animation on scroll"

import { animate, onScroll } from 'animejs';

animate('.section', {
  opacity: [0, 1],
  y: [50, 0],
  duration: 800,
  autoplay: onScroll({ target: '.section' })
});

"Use with React"

import { createScope, animate } from 'animejs';
import { useEffect, useRef } from 'react';

function Component() {
  const root = useRef(null);
  const scope = useRef(null);
  useEffect(() => {
    scope.current = createScope({ root }).add(() => {
      animate('.target', { opacity: [0, 1] });
    });
    return () => scope.current.revert();
  }, []);
  return <div ref={root}><div className="target">Hello</div></div>;
}

Decision Trees

Which API to Use

NeedUseImport
Basic CSS animationwaapi.animate()import { waapi } from 'animejs'
JS objects, SVG attrs, callbacksanimate()import { animate } from 'animejs'
Sequenced multi-elementcreateTimeline()import { createTimeline } from 'animejs'
Scroll-triggeredonScroll() in autoplayimport { onScroll } from 'animejs'
Drag interactionscreateDraggable()import { createDraggable } from 'animejs'
Layout changes (FLIP)createLayout()import { createLayout } from 'animejs'
Reactive valuescreateAnimatable()import { createAnimatable } from 'animejs'
Text splittingsplitText()import { splitText } from 'animejs'
SVG morphingsvg.morphTo()import { svg } from 'animejs'
SVG drawingsvg.createDrawable()import { svg } from 'animejs'
SVG motion pathsvg.createMotionPath()import { svg } from 'animejs'

Easing Selection

ContextEasingWhy
UI entrance'out(3)' to 'out(4)'Fast start, gentle stop
UI exit'in(3)'Slow start, quick exit
Hover/click feedbackspring({ bounce: 0.5 })Natural rebound
Looping/ambient'inOut(2)'Symmetric, smooth
Scroll scrubbing'linear'Direct 1:1 mapping
Bouncy entrance'outBounce'Playful landing
Elastic snap'outElastic'Overshoot + settle

Animation Timing Guidelines

Element TypeDurationDelay Pattern
Micro-interaction (hover, click)150-300msNone
UI feedback (toggle, switch)200-400msNone
Content entrance400-800msstagger(50-150)
Page transition300-600msSequential
Hero reveal600-1200msstagger(100-200)
Scroll parallaxMatch scroll'linear' scrub
Loading/ambient1000-3000msLoop

v3 to v4 Migration

v3 (Old)v4 (New)
anime({ targets, ... })animate(targets, { ... })
anime.timeline()createTimeline()
anime.stagger()stagger()
direction: 'alternate'alternate: true
direction: 'reverse'reversed: true
easing: 'easeOutExpo'ease: 'outExpo'
anime.remove()animation.revert()

Utilities Quick Reference

import { utils } from 'animejs';
// or import individual utilities

utils.$('.selector')     // Query elements (returns array)
utils.get(el, 'prop')    // Get computed property value
utils.set(el, { x: 100 }) // Set properties immediately
utils.remove(animation)  // Remove animation
utils.sync(a, b)         // Sync two animations
utils.random(0, 100)     // Random number in range
utils.clamp(0, value, 100) // Clamp value
utils.mapRange(0, 1, 0, 100, 0.5) // Map value between ranges
utils.lerp(0, 100, 0.5)  // Linear interpolation
utils.snap(10, value)     // Snap to nearest increment

Common Gotchas

ProblemCauseFix
Animation not visibleElement has opacity: 0 in CSSSet initial state or use from parameter
Janky animationAnimating width/height/top/leftUse transform (x, y, scale) instead
Memory leak in SPANot cleaning up animationsscope.revert() in cleanup
React double-fireStrictMode runs effects twicecreateScope() + cleanup handles this
Animation stacksMultiple triggers without cancelCall .revert() before re-creating
WAAPI missing featuresUsing JS-only features with waapiSwitch to animate() for full API
Layout animation flickerNo explicit dimensionsSet CSS width/height before animating

Reference Files

FileContents
references/core-api.mdanimate() function, targets, properties, tweens, keyframes, playback, callbacks, methods, WAAPI variant
references/timelines-and-scope.mdcreateTimeline(), time positions, createScope(), React integration pattern
references/scroll-and-events.mdonScroll(), ScrollObserver settings, thresholds, sync modes, scroll patterns
references/svg-and-text.mdSVG morphTo/createDrawable/createMotionPath, splitText(), text animation patterns
references/interactive-features.mdcreateDraggable(), createLayout() (FLIP), createAnimatable(), interaction patterns
references/easing-and-performance.mdEasing functions, spring physics, stagger(), WAAPI vs JS, engine config, performance
references/website-animation-recipes.mdProduction-ready recipes: hero, scroll reveals, nav, micro-interactions, page transitions

Command Palette

Search skills, docs, and navigate Tank