1. 開発者向けのウェブ技術
  2. CSS
  3. リファレンス
  4. プロパティ
  5. transition-delay

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

View in English Always switch to English

transition-delay

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年9月以降、すべてのブラウザーで利用可能です。

CSStransition-delay プロパティは、値が変更されたときにプロパティのトランジション効果が始まるまでの待ち時間を指定します。

試してみましょう

transition-delay: 250ms;
transition-property: margin-right;
transition-delay: 1s;
transition-property: background-color;
transition-delay: 1s;
transition-property: margin-right, color;
transition-delay: 1s, 250ms;
transition-property: margin-right, color;
<section id="default-example">
 <div id="example-element">トランジションを見るには<br />ポインターを当ててください</div>
</section>
#example-element {
 background-color: #e4f0f5;
 color: black;
 padding: 1rem;
 border-radius: 0.5rem;
 font: 1em monospace;
 width: 100%;
 transition: margin-right 2s;
}
#default-example:hover > #example-element {
 background-color: #990099;
 color: white;
 margin-right: 40%;
}

待ち時間はゼロ、正の数、負の数で指定します。

  • 0s (または 0ms) の値は直ちにトランジション効果が始まります。
  • 正の数の場合は、指定された時間の長さの分だけトランジション効果が始まるのが遅れます。
  • 負の数の場合は、直ちにトランジション効果が、効果の途中から始まります。言い換えれば、効果は指定された時間の長さの分だけ既に実行されていたかのように動きます。

複数の待ち時間を指定することができ、複数のプロパティのトランジションを行うときに有用です。それぞれの待ち時間は、マスターリストである transition-property プロパティによって指定された対応するプロパティに適用されます。マスターリストよりも指定された待ち時間が少ない場合は、充足するまで待ち時間のリストが繰り返して使用されます。また待ち時間の数が多い場合は、リストが適切な長さに切り詰められます。どちらの場合も、 CSS の宣言として妥当です。

構文

css
/* <time> 値 */
transition-delay: 3s;
transition-delay: 2s, 4ms;
/* グローバル値 */
transition-delay: inherit;
transition-delay: initial;
transition-delay: revert;
transition-delay: revert-layer;
transition-delay: unset;

<time>

プロパティの値が変化してからトランジション効果が始まるまでの待ち時間を記述します。

公式定義

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

形式文法

transition-delay = 
<time> #
この構文は CSS Transitions Module Level 1 による最新の標準を反映しています。すべてのブラウザーがすべての部分を実装しているわけではありません。サポート情報についてはブラウザーの互換性を参照してください。

様々な待ち時間を示す例

HTML

html
<div class="box delay-1">0.5 秒</div>
<div class="box delay-2">2 秒</div>
<div class="box delay-3">4 秒</div>
<button id="change">変更</button>

CSS

css
.box {
 margin: 20px;
 padding: 10px;
 display: inline-block;
 width: 100px;
 height: 100px;
 background-color: red;
 font-size: 18px;
 transition-property: background-color, font-size, transform, color;
 transition-timing-function: ease-in-out;
 transition-duration: 3s;
}
.transformed-state {
 transform: rotate(270deg);
 background-color: blue;
 color: yellow;
 font-size: 12px;
 transition-property: background-color, font-size, transform, color;
 transition-timing-function: ease-in-out;
 transition-duration: 3s;
}
.delay-1 {
 transition-delay: 0.5s;
}
.delay-2 {
 transition-delay: 2s;
}
.delay-3 {
 transition-delay: 4s;
}

JavaScript

js
function change() {
 const elements = document.querySelectorAll("div.box");
 for (const element of elements) {
 element.classList.toggle("transformed-state");
 }
}
const changeButton = document.querySelector("#change");
changeButton.addEventListener("click", change);

結果

仕様書

仕様書
CSS Transitions Module Level 1
# transition-delay-property

ブラウザーの互換性

関連情報

MDN の改良に協力

協力方法を知る

このページは MDN の貢献者によって に最終更新されました。

AltStyle によって変換されたページ (->オリジナル) /