transition

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> || <easing-function> || <time>

where
<single-transition-property> = all | <custom-ident>
<easing-function> = linear | <cubic-bezier-timing-function> | <step-timing-function>

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

where
<step-position> = jump-start | jump-end | jump-none | jump-both | start | end

範例

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
Computed valueas each of the properties of the shorthand:
Animation typediscrete

瀏覽器支援情況

BCD tables only load in the browser

更多資訊