デモを読み込み中...
スコアカード
| ライブラリ | 実装行数 | 使用API | 主観メモ |
|---|---|---|---|
| Anime.js | 8行 | animate / delay関数(or stagger) | from:'random'が組み込みで一番手軽 |
| Motion | 9行 | animate / delay関数 | 同型で書ける。秒単位への換算だけ注意 |
コード比較
import { animate } from "animejs";
// 文字spanへの分解は自前ユーティリティで共通化(両者へ同じDOMを渡す)
// delayに関数値を渡すと任意順序の遅延を作れる
animate(chars, {
y: [28, 0],
opacity: [0, 1],
duration: 600,
ease: "outCubic",
delay: (_target, i) => order[i] * 60,
});
// 単純な順送りなら stagger(60) 、ランダムなら
// stagger(60, { from: "random" }) という近道もあるimport { animate } from "motion";
// delayへ関数を渡す点は同じ。単位が秒なことに注意
animate(
chars,
{ y: [28, 0], opacity: [0, 1] },
{
duration: 0.6,
ease: [0.33, 1, 0.68, 1], // outCubic相当のcubic-bezier
delay: (i) => (order[i] * 60) / 1000,
},
);
// 有料のsplitText()を使えば分解処理ごと任せることもできる- -文字分解そのものはどちらのライブラリの仕事でもないため、共通ユーティリティでspan化して同じDOMを渡した。純粋に遅延制御の書き味比較になる。
- -どちらもdelayに関数を渡せるためコードはほぼ同型。違いは時間単位(ms/秒)とイージング指定(名前文字列/cubic-bezier配列)くらい。
- -MotionにはsplitText(Motion+有料)という分解ユーティリティがあり、Anime.jsにはtext.split()ユーティリティがある。実務では分解処理込みで選定するとよい。