mcpField
A
animejs

animejs

github.com/freshtechbroデザイン・UI1.2k2.8k 回インストール49 週間前に更新
リポジトリ

animejs について

animejs は、DOM 要素、CSS、SVG、JavaScript オブジェクトを扱う Web 開発者向けの JavaScript アニメーションライブラリです。タイムライン制御やスタッガー機能を備え、特定のフレームワークに依存しません。

主な機能

  1. 01相対位置を使ったタイムライン制御
  2. 02複数要素のスタッガーアニメーション
  3. 03SVG パスの描画とモーフィング
  4. 04柔軟なタイミング設定のキーフレーム
  5. 05スプリングとカスタムイージング
  6. 06再生・一時停止・ループ制御

活用シーン

  1. 01複数の UI 要素の動きを連続して構成
  2. 02グリッド項目を順に表示
  3. 03SVG パスの描画や形状変化
  4. 04さまざまな JavaScript フレームワークでのアニメーション

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/freshtechbro/claudedesignskills --skill animejs

インストール後、Claude Code で/animejsを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

assets/
README.md
references/
api_reference.md
stagger_guide.md
timeline_guide.md
scripts/
animation_generator.py
timeline_builder.py

詳細

Anime.js

Web アニメーション向けの、強力なタイムライン機能とスタッガー機能を備えた軽量な JavaScript アニメーションライブラリです。

概要

Anime.js(「アニメ JS」と発音します)は、DOM 要素、CSS プロパティ、SVG 属性、JavaScript オブジェクトを扱える多用途のアニメーションエンジンです。React 専用のライブラリとは異なり、Anime.js はバニラ JavaScript やあらゆるフレームワークで動作します。

このスキルを使う場面:

  • 精密な演出を伴う、タイムラインベースのアニメーションシーケンス
  • 複数の要素にまたがるスタッガーアニメーション
  • SVG パスのモーフィングや描画アニメーション
  • パーセンテージベースのタイミングによるキーフレームアニメーション
  • フレームワークに依存しないアニメーション(React、Vue、バニラ JS で動作)
  • 複雑なイージング関数(spring、steps、cubic-bezier)

主な機能:

  • 相対位置指定に対応したタイムラインシーケンス
  • 強力なスタッガーユーティリティ(グリッド、中央から、イージング)
  • SVG のモーフィングとパスアニメーション
  • 組み込みのスプリング物理イージング
  • 柔軟なタイミング指定に対応したキーフレーム
  • 小さなバンドルサイズ(gzip 圧縮時約 9KB)

主な概念

基本的なアニメーション

anime() 関数でアニメーションを作成します。

import anime from 'animejs'

anime({
  targets: '.element',
  translateX: 250,
  rotate: '1turn',
  duration: 800,
  easing: 'easeInOutQuad'
})
ターゲット

アニメーションのターゲットを指定する方法はいくつかあります。

// 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 })
アニメーション可能なプロパティ

CSS プロパティ:

anime({
  targets: '.element',
  translateX: 250,
  scale: 2,
  opacity: 0.5,
  backgroundColor: '#FFF'
})

CSS トランスフォーム(個別):

anime({
  targets: '.element',
  translateX: 250,   // Individual transform
  rotate: '1turn',   // Not 'transform: rotate()'
  scale: 2
})

SVG 属性:

anime({
  targets: 'path',
  d: 'M10 80 Q 77.5 10, 145 80', // Path morphing
  fill: '#FF0000',
  strokeDashoffset: [anime.setDashoffset, 0] // Line drawing
})

JavaScript オブジェクト:

const obj = { value: 0 }
anime({
  targets: obj,
  value: 100,
  round: 1,
  update: () => console.log(obj.value)
})
タイムライン

精密に制御しながら複雑なシーケンスを作成します。

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

よくあるパターン

1. スタッガーアニメーション(順次表示)
anime({
  targets: '.stagger-element',
  translateY: [100, 0],
  opacity: [0, 1],
  delay: anime.stagger(100), // Increase delay by 100ms
  easing: 'easeOutQuad',
  duration: 600
})
2. 中央からのスタッガー
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 の線描画
anime({
  targets: 'path',
  strokeDashoffset: [anime.setDashoffset, 0],
  easing: 'easeInOutQuad',
  duration: 2000,
  delay: (el, i) => i * 250
})
4. SVG のモーフィング
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. タイムラインシーケンス
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. キーフレームアニメーション
anime({
  targets: '.element',
  keyframes: [
    { translateX: 100 },
    { translateY: 100 },
    { translateX: 0 },
    { translateY: 0 }
  ],
  duration: 4000,
  easing: 'easeInOutQuad',
  loop: true
})
7. スクロールをトリガーにしたアニメーション
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)
})

統合パターン

React との連携
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>
}
Vue との連携
export default {
  mounted() {
    anime({
      targets: this.$el,
      translateX: 250,
      duration: 800
    })
  }
}
パス追従アニメーション
const path = anime.path('#motion-path')

anime({
  targets: '.element',
  translateX: path('x'),
  translateY: path('y'),
  rotate: path('angle'),
  easing: 'linear',
  duration: 2000,
  loop: true
})

高度なテクニック

スプリングイージング
anime({
  targets: '.element',
  translateX: 250,
  easing: 'spring(1, 80, 10, 0)', // mass, stiffness, damping, velocity
  duration: 2000
})
ステップイージング
anime({
  targets: '.element',
  translateX: 250,
  easing: 'steps(5)',
  duration: 1000
})
カスタムベジェ
anime({
  targets: '.element',
  translateX: 250,
  easing: 'cubicBezier(.5, .05, .1, .3)',
  duration: 1000
})
方向とループ
anime({
  targets: '.element',
  translateX: 250,
  direction: 'alternate', // 'normal', 'reverse', 'alternate'
  loop: true,             // or number of iterations
  easing: 'easeInOutQuad'
})
再生制御
const animation = anime({
  targets: '.element',
  translateX: 250,
  autoplay: false
})

animation.play()
animation.pause()
animation.restart()
animation.reverse()
animation.seek(500) // Seek to 500ms

パフォーマンスの最適化

Transform と Opacity を使う
// ✅ Good: GPU-accelerated
anime({
  targets: '.element',
  translateX: 250,
  opacity: 0.5
})

// ❌ Avoid: Triggers layout
anime({
  targets: '.element',
  left: '250px',
  width: '500px'
})
類似したアニメーションをまとめる
// ✅ Single animation for multiple targets
anime({
  targets: '.multiple-elements',
  translateX: 250
})

// ❌ Avoid: Multiple separate animations
elements.forEach(el => {
  anime({ targets: el, translateX: 250 })
})
複雑なアニメーションには will-change を使う
.animated-element {
  will-change: transform, opacity;
}
スクロールアニメーションでは自動再生を無効にする
const animation = anime({
  targets: '.element',
  translateX: 250,
  autoplay: false // Control manually
})

よくある落とし穴

1. 単位の種類を指定し忘れる
// ❌ Wrong: No unit
anime({ targets: '.element', width: 200 })

// ✅ Correct: Include unit
anime({ targets: '.element', width: '200px' })
2. CSS の transform プロパティを直接使う
// ❌ Wrong: Can't animate transform string
anime({ targets: '.element', transform: 'translateX(250px)' })

// ✅ Correct: Individual transform properties
anime({ targets: '.element', translateX: 250 })
3. アニメーションのクリーンアップを処理しない
// ❌ Wrong: Animation continues after unmount
useEffect(() => {
  anime({ targets: ref.current, translateX: 250 })
}, [])

// ✅ Correct: Pause on cleanup
useEffect(() => {
  const anim = anime({ targets: ref.current, translateX: 250 })
  return () => anim.pause()
}, [])
4. アニメーション対象の要素が多すぎる
// ❌ Avoid: Animating 1000+ elements
anime({ targets: '.many-items', translateX: 250 }) // 1000+ elements

// ✅ Better: Use CSS animations for large sets
// Or reduce element count with virtualization
5. タイムラインのタイミングが正しくない
// ❌ Wrong: Missing offset operator
.add({ targets: '.el2' }, '500') // Treated as absolute time

// ✅ Correct: Use relative operators
.add({ targets: '.el2' }, '-=500') // Relative to previous
.add({ targets: '.el3' }, '+=200') // Relative to previous
6. ループを使いすぎる
// ❌ Avoid: Infinite loops drain battery
anime({
  targets: '.element',
  rotate: '1turn',
  loop: true,
  duration: 1000
})

// ✅ Better: Use CSS animations for infinite loops
@keyframes rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

リソース

スクリプト
  • animation_generator.py - Anime.js のアニメーション用ボイラープレートを生成します(8 種類)
  • timeline_builder.py - 複雑なタイムラインシーケンスを構築します
リファレンス
  • api_reference.md - Anime.js API の完全なドキュメント
  • stagger_guide.md - スタッガーユーティリティとパターン
  • timeline_guide.md - タイムラインシーケンスの詳細解説
アセット
  • starter_animejs/ - サンプル付きのバニラ JS + Vite テンプレート
  • examples/ - 実用的なパターン(SVG のモーフィング、スタッガーグリッド、タイムライン)

関連スキル

  • gsap-scrolltrigger - より強力なタイムライン機能とスクロール連携
  • motion-framer - React 専用の宣言的アニメーション
  • react-spring-physics - 物理ベースのスプリングアニメーション
  • lightweight-3d-effects - シンプルな 3D エフェクト(Zdog、Vanta.js)

Anime.js と GSAP の比較:SVG を多用するアニメーション、よりシンプルなプロジェクト、またはバンドルサイズを重視する場合は Anime.js を使います。スクロール駆動の複雑なエクスペリエンス、高度なタイムライン、プロフェッショナル向けの精密な制御には GSAP を使います。

Anime.js と Framer Motion の比較:フレームワークに依存しないプロジェクトや、React 以外で作業する場合は Anime.js を使います。ジェスチャー連携を備えた React 専用の宣言的アニメーションには Framer Motion を使います。

コメント