transition
讓我們可以在給定的時間內平滑的改變屬性的值。- 要呈現
transition
效果,必須達成兩件事:- 要添加效果的 CSS 屬性
- 效果的持續時間
NOTE: 如果沒有給定持續時間, transition
將不會有效果,因為 default 值為 0。
div { | |
width: 100px; | |
height: 100px; | |
background-color: red; | |
transition: width 2s; | |
} | |
div:hover { | |
width: 300px; | |
} |
div { | |
width: 100px; | |
height: 100px; | |
background-color: red; | |
transition: width 2s, height 4s; | |
} | |
div:hover { | |
width: 300px; | |
height: 300px; | |
} |
div { | |
width: 100px; | |
height: 100px; | |
background-color: red; | |
transition: width 2s, height 2s, transform 2s | |
} | |
div:hover { | |
width: 300px; | |
height: 300px; | |
transform: rotate(180deg); | |
} |
# Speed curve of Transition
transition-timing-function
指定了 transition
效果的速度曲線。
Example
https://www.w3schools.com/css/tryit.asp?filename=trycss3_transition_speed
# Transition Delay
transition-delay
可以指定效果的延遲 (in seconds)。
/* 1 second delay before starting */ | |
div { | |
transition-delay: 1s; | |
} |