Anime.jsvsMotionラボ

トップ/お題

スクロール連動Anime.js vs Motion

お題スクロールコンテナ内で、上部進捗バーのスクラブ・セクション内ボックスの水平移動・カードの入場フェードをスクロールに連動させる。

デモを読み込み中...

スコアカード

実装スコアカード
ライブラリ実装行数使用API主観メモ
Anime.js18animate / onScroll(sync,enter,leave)1つのAPIで全部できるが閾値記法に慣れが必要
Motion16scroll / inView / animate役割分担が明快で解除も関数呼び出しだけ

コード比較

import { animate, onScroll } from "animejs";

// ScrollObserverをautoplayへ渡す設計。
// sync: true でスクロール量に同期(スクラブ)、省略すると閾値トリガー再生
animate(bar, {
  scaleX: [0, 1],
  ease: "linear",
  autoplay: onScroll({
    container,
    target: inner,
    enter: "top top",
    leave: "bottom bottom",
    sync: true,
  }),
});

// 閾値トリガー(入場したら再生)
animate(box, {
  x: 180,
  rotate: 360,
  autoplay: onScroll({ container, target: section }),
});

// 後始末: animation.revert() と observer.revert()