animation-direction

CSSanimation-direction プロパティは、アニメーション再生の向きを順方向、逆方向、前後反転のいずれにするかを設定します。

試してみましょう

アニメーションのプロパティすべてを一度に設定するには、一括指定プロパティである animation プロパティを使用すると便利です。

構文

/* 単一のアニメーション */
animation-direction: normal;
animation-direction: reverse;
animation-direction: alternate;
animation-direction: alternate-reverse;

/* 複数のアニメーション */
animation-direction: normal, reverse;
animation-direction: alternate, reverse, normal;

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

normal

アニメーションを毎回順方向に再生します。言い換えれば、アニメーション周期ごとに、アニメーションを最初の状態にリセットしてそこからまた始めます。これが既定値です。

reverse

アニメーションを毎回逆方向に再生します。言い換えれば、アニメーション周期ごとに、アニメーションを最後の状態にリセットしてそこからまた始めます。アニメーションを逆方向に実行し、タイミング関数も逆になります。例えば、タイミング関数の ease-inease-out になります。

alternate

アニメーションを毎回反転させ、初回は順方向になります。周期が偶数か奇数かを特定する回数は1から始まります。

alternate-reverse

アニメーションを毎回反転させ、初回は逆方向になります。周期が偶数か奇数かを特定する回数は1から始まります。

メモ: animation-* プロパティにコンマ区切りで複数の値を指定した場合、 animation-name プロパティで指定したアニメーションに割り当てられますが、いくつあるかによって異なる方法で割り当てられます。詳しくは、複数のアニメーションプロパティ値の設定を参照してください。

公式定義

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

形式文法

animation-direction = 
<single-animation-direction>#

<single-animation-direction> =
normal |
reverse |
alternate |
alternate-reverse

逆方向に実行されるアニメーション

HTML

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

CSS

.box {
  background-color: rebeccapurple;
  border-radius: 10px;
  width: 100px;
  height: 100px;
  animation-name: rotate;
  animation-duration: 0.7s;
  animation-direction: reverse;
}

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

結果

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

仕様書

Specification
CSS Animations Level 1
# animation-direction

ブラウザーの互換性

BCD tables only load in the browser

関連情報