过渡 | transition (Animations & Transitions) - CSS 中文开发手册 - Break易站
过渡 | transition (Animations & Transitions) - CSS 中文开发手册
transition CSS属性是transition-property,transition-duration,transition-timing-function和transition-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 transition-duration: 0s transition-property: alltransition-timing-function: ease
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 specifiedtransition-duration: as specifiedtransition-property: as specifiedtransition-timing-function: as specified
Animation type discrete Canonical order order of appearance in the formal grammar of the values
语法
transition属性被指定为一个或多个单独属性转换,用逗号分隔。
每个单属性过渡描述应被应用到单个属性(或特殊值all和none)。这包括:
零个或一个值代表过渡应适用的财产。这可能是以下任何一种:关键字 none 关键字 all 一个<custom-ident>命名的CSS属性。<single-transition-timing-function>表示要使用的计时功能的零个或一个值零个,一个或两个<time>值。第一个可以作为时间分析的值被分配给transition-duration,第二个值可以在分配transition-delay时间时被分析transition-delay。
当属性值列表长度不相同时,看看事情是如何处理的。简而言之,超出实际动画属性数量的额外转换描述将被忽略。
形式语法
<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 Draft | Initial definition |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1.0 -webkit 26.0 # | (Yes)-webkit (Yes) | 4.0 (2.0) -moz 16.0 (16.0)1 | 10.0 | 10.1 -o 12.10 # | 3.0 -webkit 6.1 |
Gradients2 | No support | (Yes) | No support | 10.0 | No support | No support |
frames() timing function | No support3 | ? | No support3 | No support | No support3 | ? |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 2.1 -webkit | (Yes)-webkit (Yes) | 4.0 (2.0) -moz 16.0 (16.0)1 | 10.0 | 10.0 -o 12.10 # | 3.2 -webkit |
Gradients1 | No support | (Yes) | No support | 10.0 | No support | No support |
frames() timing function | ? | ? | No support3 | No support | (Yes) | ? |