コンテンツへスキップ

タイムライン

アニメーションを連結するにはtlを使います。GSAPアダプターはネイティブのタイムラインを作成し、MotionアダプターはMotionシーケンスを作成します。以下の例ではGSAPを使っています。サポートされているイージングとタイムライン設定については、Motionガイドを参照してください。

基本のタイムライン

tlを追加してタイムラインコンテナを作成します:

HTML
<div data-animate="tl defaults:ease-elastic|duration-1">
  <div data-animate="to:rotate-360"></div>
  <div data-animate="to:rotate-360"></div>
</div>

仕様上、Glazeはタイムライン宣言要素のすべての子要素をタイムラインのスコープに含めます。明示的に指定する必要はありません。

タイムラインのデフォルト値

タイムライン全体のデフォルト値を設定します:

HTML
<div data-animate="tl defaults:ease-elastic|duration-4 repeat-1 yoyo-true">
  ...
</div>

タイムライン要素では、tlの後の文字列でGSAPタイムライン自体のオプションを設定します。通常のkey-value部分はトップレベルのオプション(repeat-1、yoyo-true)を設定し、key:にパイプ区切りの値を続けるとネストされたオプションを設定します。defaults:ease-elastic|duration-4はdefaults: { ease: "elastic", duration: 4 }になり、scrollTrigger:trigger-[&]はscrollTrigger: { trigger: element }になります。scrollTrigger.trigger-[&]のようなドット記法は、要素のfrom:またはto:プロパティ内でのみ使用できます。

タイミングの調整

tl:を使って、子アニメーションの開始タイミングを調整します:

HTML
<div data-animate="tl defaults:ease-elastic|duration-4">
  <div data-animate="to:rotate-360"></div>
  <div data-animate="tl:[-=3] to:rotate-360"></div>
</div>
HTML
<div
  class="grid gap-8"
  data-animate="tl defaults:ease-elastic|duration-4 scrollTrigger:trigger-[&]"
>
  <div
    class="h-20 w-20 rounded-xl bg-amber-500"
    data-animate="to:rotate-360"
  ></div>
  <div
    class="h-20 w-20 rounded-xl bg-green-500"
    data-animate="tl:[-=3] to:rotate-360"
  ></div>
</div>

tl:[-=3]は「前のアニメーションが終わる3秒前に開始する」(重なり)という意味です。

よく使われるタイミング値:

  • tl:[+=1] - 前のアニメーションが終了してから1秒後に開始
  • tl:[-=1] - 前のアニメーションが終了する1秒前に開始(重なり)
  • tl:[<] - 前のアニメーションと同時に開始

レスポンシブなタイムライン

ブレークポイントとタイムラインを組み合わせます:

HTML
<div data-animate="tl defaults:ease-power2.inOut|duration-2">
  <div data-animate="to:rotate-360 @lg:to:xPercent-[50]"></div>
  <div data-animate="tl:[-=1] to:rotate-360 @lg:to:xPercent-[-50]"></div>
</div>
HTML
<div
  class="grid gap-8"
  data-animate="tl defaults:ease-power2.inOut|duration-2 scrollTrigger:trigger-[&]"
>
  <div
    class="h-20 w-20 rounded-xl bg-amber-500"
    data-animate="to:rotate-360 @lg:to:xPercent-[100]"
  ></div>
  <div
    class="h-20 w-20 rounded-xl bg-green-500"
    data-animate="tl:[-=1] to:rotate-360 @lg:to:xPercent-[-100]"
  ></div>
</div>

回転は常に実行されますが、横方向の移動は大画面でのみ始まります。

名前付きタイムライン

タイムラインに名前を付けると、どこからでも参照できます:

HTML
<div data-animate="tl/main defaults:ease-power2.inOut|duration-2">
  <div data-animate="to:rotate-360"></div>
</div>

<!-- Somewhere else in the DOM -->
<div data-animate="tl:main-[-=1] to:scale-1.5">...</div>
HTML
<div class="grid w-full grid-cols-2 justify-items-center">
  <div
    class="grid gap-8"
    data-animate="tl/main defaults:ease-power2.inOut|duration-2 scrollTrigger:trigger-[&]"
  >
    <div
      class="h-20 w-20 rounded-xl bg-amber-500"
      data-animate="to:rotate-360"
    ></div>
    <div
      class="h-20 w-20 rounded-xl bg-green-500"
      data-animate="tl:[-=1] to:rotate-360"
    ></div>
  </div>
  <div
    class="tl grid gap-8"
    data-animate="tl:main-[-=1] [&>div]:to:rotate-360|stagger-0.25"
  >
    <div class="h-20 w-20 rounded-xl bg-rose-500"></div>
    <div class="h-20 w-20 rounded-xl bg-red-500"></div>
  </div>
</div>

tl/nameで名前付きタイムラインを作成し、tl:nameで参加します。