DOM

Animation.currentTime プロパティ

 編集:2022.10.20 by T.A.

[Edge]。→

アニメーション Animation の現在の時間値をミリ秒単位の数値で取得/設定します。実行中か一時停止中に関わらず。

アニメーションにタイムラインがない場合、非アクティブであり、または、まだプレイしていない場合は null です。

構文
Animation.currentTime
Animation Animation

現在の時間をミリ秒で表す数値、または null(アニメーションが無効(再生されていない))。

mdn: 現在の時間をミリ秒で表す数値、またはアニメーションを無効にする null。

currentTime の取得と設定

HTML:

<DIV id=IdTest style="width:1em">■</DIV>
<SPAN id=IdLog></SPAN>

JavaScript:

KF=new KeyframeEffect(  //キーフレームの指定:
  IdTest, 
  [
    {transform:'translateX(0)'}, {transform:'translateX(200px)'}  //X軸移動。
  ], 
  {duration:3000, fill:'forwards'}  //3000ms掛けて、?。
);
Ani=new Animation(KF, document.timeline);  //アニメーション再生。
Ani.play();

JavaScript: currentTime を得る。

D=Ani.currentTime;  //=[number]:1035.5730000139401。サンプル値。

JavaScript: 設定。

Ani.currentTime=2000;  //Failed to set the 'currentTime' property on 'Animation': currentTime may not be changed from resolved to unresolved
	//「Animation」で「currentTime」プロパティを設定できませんでした: currentTime を解決済みから未解決に変更できない可能性があります

↑途中から動作した。

JavaScript: null を設定。

Ani.currentTime=null;  //エラー発生: Failed to set the 'currentTime' property on 'Animation': currentTime may not be changed from resolved to unresolved
	//「Animation」で「currentTime」プロパティを設定できませんでした: currentTime を解決済みから未解決に変更できない可能性があります

KeyframeEffect()CSS:transformCSS:translateX()duration、fillplay()


テスト