このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

animation-duration

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年9月⁩.

* Some parts of this feature may have varying levels of support.

animation-durationCSS のプロパティで、 1 回のアニメーション周期が完了するまでの再生時間を設定します。

試してみましょう

animation-duration: 750ms; 
animation-duration: 3s; 
animation-duration: 0s; 
<section class="flex-column" id="default-example"> <div class="animating" id="example-element"></div> <button id="play-pause">再生</button> </section> 
#example-element { animation-direction: alternate; animation-iteration-count: infinite; animation-name: slide; animation-play-state: paused; animation-timing-function: ease-in; background-color: #1766aa; border-radius: 50%; border: 5px solid #333; color: white; height: 150px; margin: auto; margin-left: 0; width: 150px; } #example-element.running { animation-play-state: running; } #play-pause { font-size: 2rem; } @keyframes slide { from { background-color: orange; color: black; margin-left: 0; } to { background-color: orange; color: black; margin-left: 80%; } } 
"use strict"; window.addEventListener("load", () => { const el = document.getElementById("example-element"); const button = document.getElementById("play-pause"); button.addEventListener("click", () => { if (el.classList.contains("running")) { el.classList.remove("running"); button.textContent = "再生"; } else { el.classList.add("running"); button.textContent = "一時停止"; } }); }); 

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

構文

css
/* 単一のアニメーション */ animation-duration: auto; /* 既定値 */ animation-duration: 6s; animation-duration: 120ms; /* 複数のアニメーション */ animation-duration: 1.64s, 15.22s; animation-duration: 10s, 35s, 230ms; /* グローバル値 */ animation-duration: inherit; animation-duration: initial; animation-duration: revert; animation-duration: revert-layer; animation-duration: unset; 

auto

時間ベースのアニメーションでは、 auto0s の値と等価です(下記参照)。 CSS スクロール駆動アニメーションでは、 auto はタイムライン全体をアニメーションで埋めます。

<time>

1 回のアニメーションの周期にかかる時間。この値は、秒 (s) またはミリ秒 (ms) で指定することができます。値は正の数か 0 でなければならず、単位は必須です。

値が指定されなかった場合、既定値である 0s が使用され、この場合でもアニメーションは実行されます(animationStartanimationEnd イベントが発生します)。長さが 0s のときにアニメーションが表示されるかどうかは、下記で説明する animation-fill-mode の値によります。

  • animation-fill-modebackwards または both に設定した場合、 animation-direction で定義したアニメーションの最初のフレームが animation-delay(/ja/docs/Web/CSS/animation-delay) のカウントダウン中に表示されます。
  • animation-fill-modeforwards または both に設定した場合、アニメーションの最後のフレームは animation-delay が経過した後に、 animation-direction で定義したように表示されます。
  • animation-fill-modenone に設定すると、アニメーションは目に見える効果はありません。

メモ: 負の数は無効であり、宣言が無視されます。一部、初期の接頭辞付きの実装は 0s と等価に解釈するかもしれません。

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

メモ: CSS スクロール駆動アニメーションを作成するとき、animation-duration の値を秒やミリ秒で指定することは実際には意味がありません。テストしたところ、スクロール進行タイムラインアニメーションには効果がないように見えましたが、ビュー進行タイムラインアニメーションでは、アニメーションがタイムラインの終わりに近づいて起こるようになるようでした。しかし、Firefox がアニメーションを正常に適用するには animation-duration の設定が要求されます。そのため、Firefoxでアニメーションが動作するように animation-duration1ms に設定することをお勧めします。

公式定義

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

形式文法

animation-duration = 
[ auto | <time [0s,∞]> ]#
この構文は CSS Animations Level 2 による最新の標準を反映しています。すべてのブラウザーがすべての部分を実装しているわけではありません。サポート情報についてはブラウザーの互換性を参照してください。

アニメーション時間の設定

これは animation-duration が 0.7 秒のアニメーションです。

HTML

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

CSS

css
.box { background-color: rebeccapurple; border-radius: 10px; width: 100px; height: 100px; } .box:hover { animation-name: rotate; animation-duration: 0.7s; } @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } 

結果

矩形の上にカーソルを当てると、アニメーションを開始します。

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

仕様書

Specification
CSS Animations Level 1
# animation-duration

ブラウザーの互換性

関連情報