transition
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015å¹´9æ.
* Some parts of this feature may have varying levels of support.
transition CSS å±¬æ§æ¯ transition-propertyãtransition-durationãtransition-timing-function å transition-delay ç簡寫屬æ§ã
å試ä¸ä¸
transition: margin-right 2s;
transition: margin-right 2s 0.5s;
transition: margin-right 2s ease-in-out;
transition: margin-right 2s ease-in-out 0.5s;
transition:
margin-right 2s,
color 1s;
transition: all 1s ease-out;
<section id="default-example">
<div id="example-element">Hover to see<br />the transition.</div>
</section>
#example-element {
background-color: #e4f0f5;
color: #000;
padding: 1rem;
border-radius: 0.5rem;
font: 1em monospace;
width: 100%;
transition: margin-right 2s;
}
#default-example:hover > #example-element {
background-color: #909;
color: #fff;
margin-right: 40%;
}
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éå
©åç¹æ®å¼ï¼ãå
¶å
å«äºï¼
-
ç¡æä¸åå°æç屬æ§å稱ãå¯ä»¥æ¯ï¼
- ééµå
none - ééµå
all - 以
<custom-ident>å½åç CSS 屬æ§ã
- ééµå
-
ç¡æä¸å
<single-transition-timing-function>表示æä½¿ç¨ç漸è®å½å¼ã -
ç¡ãä¸åæå ©å
<time>å¼ã第ä¸åå¼æè¢«ææ´¾çµ¦transition-durationï¼è第äºååè¢«ææ´¾çµ¦transition-delayã
ç¶æ¯åè½å ´è¨å®ä¸çé·æï¼è«åè¦ ç¶ property values list ä¹éä¸çé·æ... ãç°¡èè¨ä¹ï¼å¤é¤çæè¿°(è¶ é實é被å·è¡çæ¸é)æç´æ¥è¢«å¿½ç¥ã
æ¨æºèªæ³
transition =
<single-transition>#
<single-transition> =
[ none | <single-transition-property> ] ||
<time> ||
<easing-function> ||
<time> ||
<transition-behavior-value>
<single-transition-property> =
all |
<custom-ident>
<easing-function> =
<linear-easing-function> |
<cubic-bezier-easing-function> |
<step-easing-function>
<transition-behavior-value> =
normal |
allow-discrete
<linear-easing-function> =
linear |
<linear()>
<cubic-bezier-easing-function> =
ease |
ease-in |
ease-out |
ease-in-out |
<cubic-bezier()>
<step-easing-function> =
step-start |
step-end |
<steps()>
<linear()> =
linear( [ <number> && <percentage>{0,2} ]# )
<cubic-bezier()> =
cubic-bezier( [ <number [0,1]> , <number> ]#{2} )
<steps()> =
steps( <integer> , <step-position>? )
<integer> =
<number-token>
<step-position> =
jump-start |
jump-end |
jump-none |
jump-both |
start |
end
ç¯ä¾
CSS è½å ´ ææ´å¤ç¯ä¾ã
è¦ç¯
| Specification |
|---|
| CSS Transitions Module Level 1 > # transition-shorthand-property > |
| é è¨å¼ | as each of the properties of the shorthand:
|
|---|---|
| é©ç¨æ¼ | ææå
ç´ ï¼::before å ::after å½å
ç´ |
| ç¹¼æ¿èå¦ | å¦ |
| Computed value | as each of the properties of the shorthand:
|
| åç«é¡å | ä¸å¯å |