With CSS3, we can add an effect to an element when the element is transformed from one style to another without using Flash animation or JavaScript.
Please move the mouse over the green block below:
CSS3 transitions are the effects of an element gradually changing from one style to another.
To achieve this, two elements must be established:
- Specify which CSS property you want to add the effect to
- Duration of the specified effect
Properties |
Description |
CSS |
Transition |
Shorthand property, which is used to set four transition properties in one property. |
3 |
Transition-property |
Specifies the name of the CSS property that the transition is applied to. |
3 |
Transition-duration |
Defines the time that the transition effect takes. The default is 0. |
3 |
Transition-timing-function |
A time curve that specifies the transition effect. The default is "ease". |
3 |
Transition-delay |
Specifies when the transition effect begins. The default is 0. |
3
|
To achieve the above green block transition effect steps:
Only one div is defined in the HTML code, and no code is given here.
CSS code: starts to animate when the mouse is positioned over the element, and the mouse is removed back to the original
div{ width:100px; height:100px; Background: #24ff39; transition-duration:2s,2s;//Set the execution time of the animation effect, the first parameter is the width change time, the second parameter is the height change time } div:hover{ width:200px; height:200px; Background: #ff1323; Transform:rotate (360deg);}
The implementation results are as follows:
CSS3 Animations: Transitions