Home > Article > Web Front-end > How to use the transition function in CSS3?
How to use the transition attribute: transition:property duration timing-function;
The property indicates which property is to be smoothly transitioned, and the duration indicates how long it takes to complete the property. Smooth transition of values, timing-function indicates the method by which smooth transition is performed.
Multiple smooth transition examples:
1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5 <meta http-equiv="x-ua-compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 7 <title>测试</title> 8 </head> 9 <body>10 <div id="test"></div>11 <style>12 #test{13 width: 500px;14 height: 500px;15 background-color: yellow;16 /*css动画*/17 transform: rotate(0);18 -webkit-transition: transform 0.5s linear, width 0.5s linear;19 -moz-transition: transform 0.5s linear, width 0.5s linear;20 -ms-transition: transform 0.5s linear, width 0.5s linear;21 -o-transition: transform 0.5s linear, width 0.5s linear;22 transition: transform 0.5s linear, width 0.5s linear;23 }24 #test:hover{25 width: 200px;26 transform: rotate(180deg);27 }28 </style>29 </body>30 </html>
Usage examples:
1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5 <meta http-equiv="x-ua-compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 7 <title>测试</title> 8 </head> 9 <body>10 <div id="test"></div>11 <style>12 /*animation动画*/13 @-webkit-keyframes colorChange {14 0%{15 background-color: deepskyblue;16 } 50%{18 background-color: red;19 }20 100%{21 background-color: deepskyblue;22 }23 }24 #test{25 width:500px;26 height: 500px;27 background-color: deepskyblue;28 }29 #test:hover{30 animation-name: colorChange; animation-duration: 1s;32 animation-timing-function: linear;33 }34 </style>35 </body>36 </html>
Method to implement animation:
Method | Change speed of attribute value |
linear | Change at the same speed at the beginning and end of the animation |
ease-in | At the beginning of the animation The speed is very slow, and then the speed increases along the curve value |
ease-out | The animation starts very fast, and then the speed slows down along the curve value |
ease | The animation starts very slowly, then speeds up along the curve value, and then slows down along the curve value |
ease-in-out | The animation starts very slowly, then speeds up along the curve value, and then slows down along the curve value |
The above is the detailed content of How to use the transition function in CSS3?. For more information, please follow other related articles on the PHP Chinese website!