在线文档教程
CSS

过渡 | transition

transition

transition CSS属性是transition-propertytransition-durationtransition-timing-functiontransition-delay的一个速记属性。

/* 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;

转换,使您能够定义元素的两种状态之间的转换。不同的状态可以使用类似的类来定义:hover:active或者使用JavaScript动态设置。

初始值as each of the properties of the shorthand: transition-delay: 0s transition-duration: 0s transition-property: all transition-timing-function: ease
应用于all elements, ::before and ::after pseudo-elements
内在no
媒体interactive
计算值as each of the properties of the shorthand: transition-delay: as specified transition-duration: as specified transition-property: as specified transition-timing-function: as specified
动画类型discrete
规范次序order of appearance in the formal grammar of the values

  • transition-delay: 0s

Applies to all elements, [`::before`](::before) and [`::after`](::after) [pseudo-elements](pseudo-elements) [Inherited](inheritance) no Media interactive [Computed value](computed_value) as each of the properties of the shorthand:

  • transition-delay: as specified

Animation type discrete Canonical order order of appearance in the formal grammar of the values

语法

transition属性被指定为一个或多个单独属性转换,用逗号分隔。

每个单属性过渡描述应被应用到单个属性(或特殊值allnone)。这包括:

  • 零个或一个值代表过渡应适用的财产。这可能是以下任何一种:

当属性值列表长度不相同时,看看事情是如何处理的。简而言之,超出实际动画属性数量的额外转换描述将被忽略。

形式语法

<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过渡文章中还包含了更多CSS过渡示例。

规范

规范状态评论
CSS TransitionsThe definition of 'transition' in that specification.Working DraftInitial definition

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support1.0 -webkit 26.0 #(Yes)-webkit (Yes)4.0 (2.0) -moz 16.0 (16.0)110.010.1 -o 12.10 #3.0 -webkit 6.1
Gradients2No support(Yes)No support10.0No supportNo support
frames() timing functionNo support3?No support3No supportNo support3?

FeatureAndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support2.1 -webkit(Yes)-webkit (Yes)4.0 (2.0) -moz 16.0 (16.0)110.010.0 -o 12.10 #3.2 -webkit
Gradients1No support(Yes)No support10.0No supportNo support
frames() timing function??No support3No support(Yes)?