CSS3

プロパティ

animation-fill-mode

  編集:2022.07.14 by T.A.

mdn

アニメーション実行の前後に適用されるスタイル設定モード。

名前 animation-fill-mode
<single-animation-fill-mode>#
初期値 none
適用対象 すべての要素
継承 されない
百分率 受容しない
算出値 リスト: 各アイテムは 指定されたキーワードを与える
正準的順序 文法に従う
アニメーション型 アニメート不可

animation-fill-mode プロパティは、アニメーション実行の時間外に適用される値を定義する。既定(初期値 none)では、アニメーションは、次に挙げる期間においては、プロパティ値には影響しない:

animation-fill-mode プロパティにより、このふるまいを上書きできる。また、このプロパティが動的に更新されたときは、アニメーションの遅延の段階/終止した後、いずれの間かに従って、必要に応じて【アニメーションが適用される】各プロパティ値にも反映されることになる。

以下のCSSが組み込んであります:

<single-animation-fill-mode>
none | forwards | backwards | both
none
アニメーションは、適用されていても、実行されていない間の効果はない。
<DIV style="border:1px solid black;
 width:200px; height:50px;
">
 <DIV style="position:relative;
  width:25px; height:25px; background:red;
  left:0px; top:0px;
  animation-name:Test;
  animation-timing-function:linear;
  animation-duration:5s;
  animation-fill-mode:none;
 "></DIV>
</DIV>

forwards
アニメーションは、終止した時点(その animation-iteration-count により決定される)のプロパティ値を、その後にも引き続き適用することになる。animation-iteration-count が正な整数の場合、アニメーションが最後の反復を完了した時点の値が適用されることになる(次の反復の開始時の値ではなく)。animation-iteration-count が 0 の場合、最初の反復の開始時の値が適用されることになる( animation-fill-mode が backwards のときと丁度同じになる)。
<DIV style="border:1px solid black;
 width:200px; height:50px;
">
 <DIV style="position:relative;
  width:25px; height:25px; background:red;
  left:0px; top:0px;
  animation-name:Test;
  animation-timing-function:linear;
  animation-duration:5s;
  animation-fill-mode:forwards;
 "></DIV>
</DIV>

backwards
アニメーションは、animation-delay により定義される遅延期間の間、[アニメーションの最初の反復を開始させる keyframe ]内で定義された一連のプロパティ値を適用することになる。この keyframe は、animation-direction 値に応じて、次のいずれかになる:
normal
alternate
from(0%)keyframe
reverse
alternate-reverse
to(100%)keyframe
<DIV style="border:1px solid black;
 width:200px; height:50px;
">
 <DIV style="position:relative;
  width:25px; height:25px; background:red;
  left:0px; top:0px;
  animation-name:Test;
  animation-timing-function:linear;
  animation-delay:3s;
  animation-duration:5s;
  animation-fill-mode:backwards;
 "></DIV>
</DIV>

both
forwardsbackwards 両効果とも適用される。
<DIV style="border:1px solid black;
 width:200px; height:50px;
">
 <DIV style="position:relative;
  width:25px; height:25px; background:red;
  left:0px; top:0px;
  animation-name:Test;
  animation-timing-function:linear;
  animation-delay:3s;
  animation-duration:5s;
  animation-fill-mode:both;
 "></DIV>
</DIV>


テスト
別画面に表示させて、
HTML:

ここに表示
HTML:

ここに表示
スクリプト:


スクリプト:



表示内容:
表示内容: