animation-play-state

animation-play-stateCSS のプロパティで、アニメーションが実行中か停止中かを設定します。

試してみましょう

停止したアニメーションを再開すると、アニメーションの流れの最初からではなく、停止した位置からアニメーションが始まります。

構文

css
/* 単一のアニメーション */
animation-play-state: running;
animation-play-state: paused;

/* 複数のアニメーション */
animation-play-state: paused, running, running;

/* グローバル値 */
animation-play-state: inherit;
animation-play-state: initial;
animation-play-state: revert;
animation-play-state: revert-layer;
animation-play-state: unset;

running

アニメーションが現在実行中です。

paused

アニメーションが現在停止中です。

メモ: animation-* プロパティにカンマ区切りで複数の値を指定した場合、 animation-name に現れる順にアニメーションに適用されます。アニメーションの数と animation-* プロパティの値が一致しない場合は、複数のアニメーションプロパティ値の設定 を参照してください。

公式定義

初期値running
適用対象すべての要素、::before / ::after 擬似要素
継承なし
計算値指定通り
アニメーションの種類アニメーション不可

形式文法

animation-play-state = 
<single-animation-play-state>#

<single-animation-play-state> =
running |
paused

アニメーションの停止

このアニメーションは停止していますが、ポインターを当てると実行されます。

HTML

html
<div class="box"></div>

CSS

css
.box {
  background-color: rebeccapurple;
  border-radius: 10px;
  width: 100px;
  height: 100px;
  animation-name: rotate;
  animation-duration: 0.7s;
  animation-iteration-count: infinite;
  animation-play-state: paused;
}

.box:hover {
  animation-play-state: running;
}

@keyframes rotate {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}

結果

矩形にポインターを当てるとアニメーションが始まります。

例については CSS アニメーションを参照してください。

仕様書

Specification
CSS Animations Level 1
# animation-play-state

ブラウザーの互換性

BCD tables only load in the browser

関連情報