翻譯不完整。請協助 翻譯此英文文件

transition CSS 屬性是 transition-property, transition-duration, transition-timing-function, and transition-delay特性簡寫

Transitions 讓你可以定義元件在兩個狀態之間切換的轉場效果。兩個不同狀態可以使用虛擬類別 定義,像是:hover:active 亦或是 使用JavaScript設定的狀態變化。

語法

/* Apply to 1 property */
/* property name | duration */
transition: margin-right 4s;

/* property name | duration | delay */
transition: margin-right 4s 1s;

/* property name | duration | timing function */
transition: margin-right 4s ease-in-out;

/* property name | duration | timing function | delay */
transition: margin-right 4s ease-in-out 1s;

/* Apply to 2 properties */
transition: margin-right 4s, color 1s;

/* Apply to all changed properties */
transition: all 0.5s ease-out;

/* Global values */
transition: inherit;
transition: initial;
transition: unset;

transition 屬性可以包含一個或多個轉場設定,每一項設定都以逗點分開。

每一項設定都描述著每一項屬性所對應的轉場效果(或是all 及 none這兩個特殊值) 。其包含了:

當每個轉場設定不等長時,請參見 當property values list 之間不等長時... 。簡而言之,多餘的描述(超過實際被執行的數量)會直接被忽略。

標準語法

<single-transition>#

where
<single-transition> = [ none | <single-transition-property> ] || <time> || <single-transition-timing-function> || <time>

where
<single-transition-property> = all | <custom-ident>
<single-transition-timing-function> = <single-timing-function>

where
<single-timing-function> = linear | <cubic-bezier-timing-function> | <step-timing-function> | <frames-timing-function>

where
<cubic-bezier-timing-function> = ease | ease-in | ease-out | ease-in-out | cubic-bezier(<number>, <number>, <number>, <number>)
<step-timing-function> = step-start | step-end | steps(<integer>[, [ start | end ] ]?)
<frames-timing-function> = frames(<integer>)

範例

CSS 轉場 有更多範例。

規範

Specification Status Comment
CSS Transitions
The definition of 'transition' in that specification.
Working Draft Initial definition

預設值as each of the properties of the shorthand:
Applies toall elements, ::before and ::after pseudo-elements
繼承與否no
Mediainteractive
Computed valueas each of the properties of the shorthand:
Animation typediscrete
Canonical orderorder of appearance in the formal grammar of the values

瀏覽器支援情況

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support

26

1 -webkit-

12

12 -webkit-

161 2 3

4 -moz-

49 -webkit-

44 -webkit- 4

10

12.1

15 -webkit-

10.1 — 15 -o-

6.1

3 -webkit-

Gradients No12 No10 No No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support

Yes

2.1 -webkit-

26

Yes -webkit-

12

12 -webkit-

161 2 3

4 -moz-

49 -webkit-

44 -webkit- 4

12.1

15 -webkit-

10.1 — 14 -o-

Yes

3.2 -webkit-

Yes

Yes -webkit-

Gradients No ? Yes No No No No

1. Before Firefox 57, transitions do not work when transitioning from a text-shadow with a color specified to a text-shadow without a color specified (see bug 726550).

2. Before Firefox 57, cancelling a filling animation (for example, with animation-fill-mode: forwards set) can trigger a transition set on the same element, although only once (see bug 1192592 and these test cases for more information).

3. Before Firefox 57, the background-position property can't be transitioned between two values containing different numbers of <position> values, for example background-position: 10px 10px; and background-position: 20px 20px, 30px 30px; (see bug 1390446).

4. From version 44: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.

更多資訊

文件標籤與貢獻者

此頁面的貢獻者: willynpi
最近更新: willynpi,