デモを読み込み中...
スコアカード
| ライブラリ | 実装行数 | 使用API | 主観メモ |
|---|---|---|---|
| Anime.js | 7行 | animate / stagger(grid) | grid stagger一発。お題そのものが得意分野 |
| Motion | 16行 | animate / delay関数(自前計算) | 距離計算を書けば同じ動きは再現できる |
コード比較
import { animate, stagger } from "animejs";
// grid指定のstaggerが組み込みなので、中心起点の波紋伝播を1行で書ける
const animation = animate(".dot", {
scale: [0, 1],
delay: stagger(40, { grid: [8, 5], from: "center" }),
duration: 500,
ease: "outQuad",
});
// 後始末: インスタンスをrevertすると初期DOMへ戻る
animation.revert();import { animate } from "motion";
// Motionのstagger()はインデックス基準のみ。
// グリッド中心からの距離ベース遅延は自前で計算する必要がある
const cols = 8;
const rows = 5;
const delays = dots.map((_, i) => {
const col = i % cols;
const row = Math.floor(i / cols);
const dist = Math.hypot(col - (cols - 1) / 2, row - (rows - 1) / 2);
return (dist * 40) / 1000; // Motionは秒単位
});
const controls = animate(
dots,
{ scale: [0, 1] },
{ duration: 0.5, ease: "easeOut", delay: (i) => delays[i] },
);
// 後始末: cancelで初期スタイルへ戻る
controls.cancel();- -Anime.jsはstagger()にgridオプションがあり、center/first/last/インデックス起点の2次元伝播を宣言的に書ける。この用途では明確に短い。
- -Motionのstagger()は1次元(インデックス順)のみ。グリッド伝播はdelayへ関数を渡して距離計算を自前実装する。柔軟だが記述量が増える。
- -時間単位はAnime.jsがミリ秒、Motionが秒。移植時に混同しやすいポイント。