CSS3 transition プロパティ
例
マウスを div 要素にホバーすると、テーブルの幅が 100px から 300px に徐々に変化します:
div
{
width:100px;
transition: width 2s;
-webkit-transition: width 2s; /* Safari */
}
div:hover {width:300px;}
試してみる »
ブラウザサポート
表内の数字は、そのプロパティをサポートする最初のブラウザバージョンを示します。
-webkit-、-ms- または -moz- の直前の数字は、その接頭辞付きプロパティをサポートする最初のブラウザバージョンを示します。
| プロパティ | |||||
|---|---|---|---|---|---|
| transition | 26.0 4.0 -webkit- |
10.0 | 16.0 4.0 -moz- |
6.1 3.1 -webkit- |
12.1 10.5 -o- |
プロパティの定義と使用説明
transition プロパティを使用すると、要素の状態が変化するときにトランジション効果を制御できます。要素があるスタイルから別のスタイルへ変化する際に、ある色から別の色へのグラデーションや、非表示から表示への変化など、滑らかなトランジション効果を生み出すことができます。
このプロパティは4つの値を含みます:
transition-property: トランジションさせる CSS プロパティの名前を指定します。例:
color、background-colorなど。transition-duration: トランジション効果の継続時間を秒またはミリ秒単位で指定します。
transition-timing-function: トランジション効果の速度曲線を指定します。指定できる値は次のとおりです:
linear(線形)、ease(イーズ)、ease-in(イーズイン)、ease-out(イーズアウト)、ease-in-out(イーズインアウト)など。transition-delay: トランジション効果が始まる前の遅延時間を秒またはミリ秒単位で指定します。
例
/* すべてのプロパティにトランジション効果を適用 */
.element {
transition: all 0.3s ease;
}
/* 指定したプロパティ(色)にトランジション効果を適用 */
.element {
transition: color 0.3s ease-in-out;
}
.element {
transition: all 0.3s ease;
}
/* 指定したプロパティ(色)にトランジション効果を適用 */
.element {
transition: color 0.3s ease-in-out;
}
| デフォルト値: | all 0 ease 0 |
|---|---|
| 継承: | no |
| バージョン: | CSS3 |
| JavaScript 構文: | object.style.transition="width 2s" |
構文
transition: property duration timing-function delay;
| 值 | 説明 |
|---|---|
| transition-property | transition 効果を適用する CSS プロパティの name を指定します |
| transition-duration | transition 効果の完了に必要な時間を秒またはミリ秒で指定します |
| transition-timing-function | transition 効果の速度曲線を指定します |
| transition-delay | transition 効果が開始するタイミングを定義します |