欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CSS3中Transition動畫屬性用法詳解

  發(fā)布時間:2016-07-04 15:17:54   作者:佚名   我要評論
這篇文章主要為大家詳細(xì)介紹了CSS3中Transition動畫屬性用法,教大家如何使用Transition動畫,感興趣的小伙伴們可以參考一下

W3C標(biāo)準(zhǔn)中對css3的transition這是樣描述的:“css的transition允許css的屬性值在一定的時間區(qū)間內(nèi)平滑地過渡。這種效果可以在鼠標(biāo)單擊、獲得焦點(diǎn)、被點(diǎn)擊或?qū)υ厝魏胃淖冎杏|發(fā),并圓滑地以動畫效果改變CSS的屬性值。”

transition屬性的值包括以下四個:

 •transition-property: 指定對HTML元素的哪個css屬性進(jìn)行過渡漸變處理,這個屬性可以是color、width、height等各種標(biāo)準(zhǔn)的css屬性。
 •transition-duration:指定屬性過渡的持續(xù)時間
 •transition-timing-function:指定漸變的速度:
1、ease:(逐漸變慢)默認(rèn)值,ease函數(shù)等同于貝塞爾曲線(0.25, 0.1, 0.25, 1.0);
2、linear:(勻速),linear 函數(shù)等同于貝塞爾曲線(0.0, 0.0, 1.0, 1.0);
3、ease-in:(加速),ease-in 函數(shù)等同于貝塞爾曲線(0.42, 0, 1.0, 1.0);
4、ease-out:(減速),ease-out 函數(shù)等同于貝塞爾曲線(0, 0, 0.58, 1.0);
5、ease-in-out:(加速然后減速),ease-in-out 函數(shù)等同于貝塞爾曲線(0.42, 0, 0.58, 1.0);
6、cubic-bezier:(該值允許你去自定義一個時間曲線), 特定的cubic-bezier曲線。 (x1, y1, x2, y2)四個值特定于曲線上點(diǎn)P1和點(diǎn)P2。所有值需在[0, 1]區(qū)域內(nèi),否則無效。
 •transition-delay:指定延遲時間,也就是經(jīng)過多長時間才開始執(zhí)行過渡過程。
 
瀏覽器兼容性

Internet Explorer 9 以及更早的版本,不支持 transition 屬性。

Internet Explorer 10, Firefox, Opera 和 Chrome支持transition 屬性。Chrome 25 以及更早的版本以及Safari 需要前綴 -webkit-。

下面還是以實(shí)例來說明transition的用法

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>transition演示1</title>  
  6.     <style type="text/css">  
  7.         .animated_div {   
  8.             margin: 100px auto;   
  9.             width:100px;   
  10.             height:60px;   
  11.             background:#92B901;   
  12.             /*簡寫屬性*/   
  13.             -webkit-transition:-webkit-transform 1s,opacity 1s,background 1s,width 1s,height 1s,font-size 1s; /* Safari */   
  14.             /*每個屬性分開寫*/   
  15.             transition-property:width,height,transform,background,opacity;   
  16.             transition-duration:1s,1s,1s,1s,1s,1s;   
  17.             -webkit-border-radius:5px;   
  18.             border-radius:5px;   
  19.             opacity:0.4;   
  20.         }   
  21.         .animated_div:hover {   
  22.             -moz-transform: rotate(360deg);   
  23.             -webkit-transform: rotate(360deg);   
  24.             -o-transform: rotate(360deg);   
  25.             transform: rotate(360deg);   
  26.             opacity:1;   
  27.             background:#1ec7e6;   
  28.             width:200px;   
  29.             height:120px;   
  30.         }   
  31.     </style>  
  32. </head>  
  33. <body>  
  34. <div class="animated_div"></div>  
  35. </body>  
  36. </html>  

上述代碼當(dāng)鼠標(biāo)移到div上時,CSS屬性:width,height,transform,background,opacity都發(fā)生漸變過渡效果。最終css樣式變成.animated_div里定義的樣式,過渡過程大致如下:

再給一個網(wǎng)上的嫦娥奔月的示例,要求:當(dāng)鼠標(biāo)移到圖片上時,嫦娥出現(xiàn),移開時嫦娥消失

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <meta charset="utf-8">  
  5.     <title>transition演示2</title>  
  6.     <style type="text/css">  
  7.         body{   
  8.           color: #fff;   
  9.           background:#000;   
  10.         }   
  11.         .change{   
  12.           display:block;   
  13.           width:400px;   
  14.           height:400px;   
  15.           background:url(http://p3.qhimg.com/t0134c65e59012a1257.png) no-repeat center;   
  16.           background-size:cover;   
  17.           border:1em solid rgba(255,255,255,.8);   
  18.           margin:50px auto;   
  19.         }   
  20.         .change img{   
  21.           display:block;   
  22.           width:300px;   
  23.           height:284px;   
  24.           opacity:0;   
  25.           -webkit-transform:translate(-100px,-100px);   
  26.           transform:translate(-100px,-100px);   
  27.           -webkit-transition:opacity 1s ease-in-out 0.5s,-webkit-transform 1s ease-in-out;   
  28.           transition: opacity 1s ease-in-out 0.5s,transform 1s ease-in-out;   
  29.         }   
  30.         .change:hover img{   
  31.           -webkit-transform:translate(0px,0px);   
  32.           transform:translate(0px,0px);   
  33.           opacity:1;   
  34.         }   
  35.     </style>  
  36. </head>  
  37. <body>  
  38.     <a href="http://image.haosou.com/i?q=%E5%AB%A6%E5%A8%A5png&src=tab_www" class="change " target="_blank">  
  39.         <img src="http://p4.qhimg.com/t0160e6a92121691e22.png" alt="" />  
  40.     </a>  
  41. </body>  
  42. </html>  

為了使嫦娥有飄入飄出的效果,設(shè)置了transform屬性,配合opacity屬性,加入過渡效果就能達(dá)到效果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論