CSS3動畫功能,css3動畫
1.transition功能
transition屬性的使用方法:transition:property duration timing-function;
其中property表示對哪個屬性進行平滑過渡,duration表示多長時間完成屬性值的平滑過渡,timing-function表示通過什麼方法來進行平滑過渡。
多平滑過渡樣本:
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>2.animation功能
使用樣本:
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 }17 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;31 animation-duration: 1s;32 animation-timing-function: linear;33 }34 </style>35 </body>36 </html>
實現動畫的方法:
| 方法 |
屬性值的變化速度 |
| linear |
在動畫開始時與結束時以同樣的速度進行變化 |
| ease-in |
動畫開始時速度很慢,然後速度沿曲線值進行加快 |
| ease-out |
動畫開始時速度很快,然後速度沿曲線值進行放慢 |
| ease |
動畫開始時速度很慢,然後速度沿曲線值進行加快,然後再沿曲線值進行放慢 |
| ease-in-out |
動畫開始時速度很慢,然後速度沿曲線值進行加快,然後再沿曲線值進行放慢 |