Animation: Animation() コンストラクター
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2020年3月以降、すべてのブラウザーで利用可能です。
Animation() はウェブアニメーション API のコンストラクターで、新しい Animation オブジェクトのインスタンスを返します。
構文
js
new Animation()
new Animation(effect)
new Animation(effect, timeline)
引数
effect省略可-
アニメーションに割り当てる、
AnimationEffectインターフェイスに基づくオブジェクトとして対象となる効果です。将来的にはSequenceEffectやGroupEffectなどの他の効果も利用できるようになるかもしれませんが、現在のところ利用できる効果はKeyframeEffectだけです。これはnull(これがデフォルト値です)にすると、効果を適用しないことを示します。 timeline省略可-
アニメーションを関連付ける
timelineを指定します。AnimationTimelineインターフェイスに基づく型のオブジェクトを指定します。デフォルト値はDocument.timelineですが、nullに設定することも可能です。
例
白うさぎを追いかけるの例では、Animation() コンストラクターを使用し、文書の timeline を利用して rabbitDownKeyframes 用の Animation を作成することができます。
js
const whiteRabbit = document.getElementById("rabbit");
const rabbitDownKeyframes = new KeyframeEffect(
whiteRabbit,
[{ transform: "translateY(0%)" }, { transform: "translateY(100%)" }],
{ duration: 3000, fill: "forwards" },
);
const rabbitDownAnimation = new Animation(rabbitDownKeyframes);
仕様書
| 仕様書 |
|---|
| Web Animations> # dom-animation-animation> |