1. 程式人生 > >CSS3 transition屬性詳解

CSS3 transition屬性詳解

默認值 -i body href margin css3 .html 時間 參與

CSS3 transition詳解

  transition:[ transition-property ] [ transition-duration ] [ transition-timing-function ] [ transition-delay ]

  transition的取值介紹:

    [ transition-property ]:檢索或設置對象中的參與過渡的屬性

    [ transition-duration ]:檢索或設置對象過渡的持續時間

    [ transition-timing-function ]:檢索或設置對象中過渡的動畫類型,主要有6個值如下:

  1. ease(逐漸變慢),默認值
  2. linear(勻速)
  3. ease-in(加速)
  4. ease-out(減速),跟ease的區別是,減速的變化程度不一樣。
  5. ease-in-out(先加速,再減速)
  6. cubic-bezier,允許你自定義一個時間曲線,通過cubic-bezier(x1,y1,x2,y2),此屬性值可以模擬以上5個狀態,只要傳入相應的x1,y1,x2,y2給cubic-bezier(x1,y1,x2,y2)。這4個值必須在[0,1]之間,否則無效。

    [ transition-delay ]:檢索或設置對象延遲過渡的時間

    

 1 <!DOCTYPE html>
 2 <html 
lang="zh-cn"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>CSS transition屬性詳解-CSS教程</title> 6 <style> 7 h1 { 8 font-size: 16px; 9 } 10 11 .test { 12 overflow
: hidden; 13 width: 100%; 14 margin: 0; 15 padding: 0; 16 list-style: none; 17 } 18 19 .test li { 20 float: left; 21 width: 100px; 22 height: 100px; 23 margin: 0 5px; 24 border: 1px solid #ddd; 25 background-color: #eee; 26 text-align: center; 27 -moz-transition: background-color .5s ease-in; 28 -webkit-transition: background-color .5s ease-in; 29 -o-transition: background-color .5s ease-in; 30 -ms-transition: background-color .5s ease-in; 31 transition: all 2s ease-in 1s; 32 } 33 34 .test li:nth-child(1):hover { 35 background-color: #F0AD4E; 36 transform: rotate(360deg); 37 } 38 39 .test li:nth-child(2):hover { 40 background-color: #999; 41 } 42 43 .test li:nth-child(3):hover { 44 background-color: #630; 45 } 46 47 .test li:nth-child(4):hover { 48 background-color: #090; 49 } 50 51 .test li:nth-child(5):hover { 52 background-color: #f00; 53 } 54 </style> 55 </head> 56 <body> 57 <h1>請將鼠標移動到下面的矩形上:</h1> 58 <ul class="test"> 59 <li>transition背景色過渡</li> 60 <li>transition背景色過渡</li> 61 <li>transition背景色過渡</li> 62 <li>transition背景色過渡</li> 63 <li>transition背景色過渡</li> 64 </ul> 65 </body> 66 </html>

CSS3 transition屬性詳解