animejs
Versatile JavaScript animation engine for DOM, CSS, SVG, and JavaScript objects. Use when creating timeline-based animations, stagger effects, SVG morphing, keyframe sequences, or complex choreographed animations. Triggers on tasks involving Anime.js, timeline animations, staggered sequences, SVG path animations, morphing, or multi-step animation choreography. Alternative to GSAP for SVG-heavy animations and React-independent projects.
What this skill does
# Anime.js
Lightweight JavaScript animation library with powerful timeline and stagger capabilities for web animations.
## Overview
Anime.js (pronounced "Anime JS") is a versatile animation engine that works with DOM elements, CSS properties, SVG attributes, and JavaScript objects. Unlike React-specific libraries, Anime.js works with vanilla JavaScript and any framework.
**When to use this skill:**
- Timeline-based animation sequences with precise choreography
- Staggered animations across multiple elements
- SVG path morphing and drawing animations
- Keyframe animations with percentage-based timing
- Framework-agnostic animation (works with React, Vue, vanilla JS)
- Complex easing functions (spring, steps, cubic-bezier)
**Core features:**
- Timeline sequencing with relative positioning
- Powerful stagger utilities (grid, from center, easing)
- SVG morphing and path animations
- Built-in spring physics easing
- Keyframe support with flexible timing
- Small bundle size (~9KB gzipped)
## Core Concepts
### Basic Animation
The `anime()` function creates animations:
```javascript
import anime from 'animejs'
anime({
targets: '.element',
translateX: 250,
rotate: '1turn',
duration: 800,
easing: 'easeInOutQuad'
})
```
### Targets
Multiple ways to specify animation targets:
```javascript
// CSS selector
anime({ targets: '.box' })
// DOM elements
anime({ targets: document.querySelectorAll('.box') })
// Array of elements
anime({ targets: [el1, el2, el3] })
// JavaScript object
const obj = { x: 0 }
anime({ targets: obj, x: 100 })
```
### Animatable Properties
**CSS Properties:**
```javascript
anime({
targets: '.element',
translateX: 250,
scale: 2,
opacity: 0.5,
backgroundColor: '#FFF'
})
```
**CSS Transforms (Individual):**
```javascript
anime({
targets: '.element',
translateX: 250, // Individual transform
rotate: '1turn', // Not 'transform: rotate()'
scale: 2
})
```
**SVG Attributes:**
```javascript
anime({
targets: 'path',
d: 'M10 80 Q 77.5 10, 145 80', // Path morphing
fill: '#FF0000',
strokeDashoffset: [anime.setDashoffset, 0] // Line drawing
})
```
**JavaScript Objects:**
```javascript
const obj = { value: 0 }
anime({
targets: obj,
value: 100,
round: 1,
update: () => console.log(obj.value)
})
```
### Timeline
Create complex sequences with precise control:
```javascript
const timeline = anime.timeline({
duration: 750,
easing: 'easeOutExpo'
})
timeline
.add({
targets: '.box1',
translateX: 250
})
.add({
targets: '.box2',
translateX: 250
}, '-=500') // Start 500ms before previous animation ends
.add({
targets: '.box3',
translateX: 250
}, '+=200') // Start 200ms after previous animation ends
```
## Common Patterns
### 1. Stagger Animation (Sequential Reveal)
```javascript
anime({
targets: '.stagger-element',
translateY: [100, 0],
opacity: [0, 1],
delay: anime.stagger(100), // Increase delay by 100ms
easing: 'easeOutQuad',
duration: 600
})
```
### 2. Stagger from Center
```javascript
anime({
targets: '.grid-item',
scale: [0, 1],
delay: anime.stagger(50, {
grid: [14, 5],
from: 'center', // Also: 'first', 'last', index, [x, y]
axis: 'x' // Also: 'y', null
}),
easing: 'easeOutQuad'
})
```
### 3. SVG Line Drawing
```javascript
anime({
targets: 'path',
strokeDashoffset: [anime.setDashoffset, 0],
easing: 'easeInOutQuad',
duration: 2000,
delay: (el, i) => i * 250
})
```
### 4. SVG Morphing
```javascript
anime({
targets: '#morphing-path',
d: [
{ value: 'M10 80 Q 77.5 10, 145 80' }, // Start shape
{ value: 'M10 80 Q 77.5 150, 145 80' } // End shape
],
duration: 2000,
easing: 'easeInOutQuad',
loop: true,
direction: 'alternate'
})
```
### 5. Timeline Sequence
```javascript
const tl = anime.timeline({
easing: 'easeOutExpo',
duration: 750
})
tl.add({
targets: '.title',
translateY: [-50, 0],
opacity: [0, 1]
})
.add({
targets: '.subtitle',
translateY: [-30, 0],
opacity: [0, 1]
}, '-=500')
.add({
targets: '.button',
scale: [0, 1],
opacity: [0, 1]
}, '-=300')
```
### 6. Keyframe Animation
```javascript
anime({
targets: '.element',
keyframes: [
{ translateX: 100 },
{ translateY: 100 },
{ translateX: 0 },
{ translateY: 0 }
],
duration: 4000,
easing: 'easeInOutQuad',
loop: true
})
```
### 7. Scroll-Triggered Animation
```javascript
const animation = anime({
targets: '.scroll-element',
translateY: [100, 0],
opacity: [0, 1],
easing: 'easeOutQuad',
autoplay: false
})
window.addEventListener('scroll', () => {
const scrollPercent = window.scrollY / (document.body.scrollHeight - window.innerHeight)
animation.seek(animation.duration * scrollPercent)
})
```
## Integration Patterns
### With React
```javascript
import { useEffect, useRef } from 'react'
import anime from 'animejs'
function AnimatedComponent() {
const ref = useRef(null)
useEffect(() => {
const animation = anime({
targets: ref.current,
translateX: 250,
duration: 800,
easing: 'easeInOutQuad'
})
return () => animation.pause()
}, [])
return <div ref={ref}>Animated</div>
}
```
### With Vue
```javascript
export default {
mounted() {
anime({
targets: this.$el,
translateX: 250,
duration: 800
})
}
}
```
### Path Following Animation
```javascript
const path = anime.path('#motion-path')
anime({
targets: '.element',
translateX: path('x'),
translateY: path('y'),
rotate: path('angle'),
easing: 'linear',
duration: 2000,
loop: true
})
```
## Advanced Techniques
### Spring Easing
```javascript
anime({
targets: '.element',
translateX: 250,
easing: 'spring(1, 80, 10, 0)', // mass, stiffness, damping, velocity
duration: 2000
})
```
### Steps Easing
```javascript
anime({
targets: '.element',
translateX: 250,
easing: 'steps(5)',
duration: 1000
})
```
### Custom Bezier
```javascript
anime({
targets: '.element',
translateX: 250,
easing: 'cubicBezier(.5, .05, .1, .3)',
duration: 1000
})
```
### Direction and Loop
```javascript
anime({
targets: '.element',
translateX: 250,
direction: 'alternate', // 'normal', 'reverse', 'alternate'
loop: true, // or number of iterations
easing: 'easeInOutQuad'
})
```
### Playback Control
```javascript
const animation = anime({
targets: '.element',
translateX: 250,
autoplay: false
})
animation.play()
animation.pause()
animation.restart()
animation.reverse()
animation.seek(500) // Seek to 500ms
```
## Performance Optimization
### Use Transform and Opacity
```javascript
// ✅ Good: GPU-accelerated
anime({
targets: '.element',
translateX: 250,
opacity: 0.5
})
// ❌ Avoid: Triggers layout
anime({
targets: '.element',
left: '250px',
width: '500px'
})
```
### Batch Similar Animations
```javascript
// ✅ Single animation for multiple targets
anime({
targets: '.multiple-elements',
translateX: 250
})
// ❌ Avoid: Multiple separate animations
elements.forEach(el => {
anime({ targets: el, translateX: 250 })
})
```
### Use `will-change` for Complex Animations
```css
.animated-element {
will-change: transform, opacity;
}
```
### Disable autoplay for Scroll Animations
```javascript
const animation = anime({
targets: '.element',
translateX: 250,
autoplay: false // Control manually
})
```
## Common Pitfalls
### 1. Forgetting Unit Types
```javascript
// ❌ Wrong: No unit
anime({ targets: '.element', width: 200 })
// ✅ Correct: Include unit
anime({ targets: '.element', width: '200px' })
```
### 2. Using CSS transform Property Directly
```javascript
// ❌ Wrong: Can't animate transform string
anime({ targets: '.element', transform: 'translateX(250px)' })
// ✅ Correct: Individual transform properties
anime({ targets: '.element', translateX: 250 })
```
### 3. Not Handling Animation Cleanup
```javascript
// ❌ Wrong: Animation continues after unmount
useEffect(() => {
anime({ tRelated in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.