亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

CSS3中Animation動畫屬性用法詳解

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

要使用animation動畫,先要熟悉一下keyframes,Keyframes的語法規(guī)則:命名是由”@keyframes”開頭,后面緊接著是這個“動畫的名稱”加上一對花括號“{}”,括號中就是一些不同時間段樣式規(guī)則。不同關(guān)鍵幀是通過from(相當(dāng)于0%)、to(相當(dāng)于100%)或百分比來表示(為了得到最佳的瀏覽器支持,建議使用百分比),如下定義一個簡單的動畫:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. @keyframes myfirst /*定義動畫名*/  
  2.     {   
  3.     0%   {background:redleft:0pxtop:0px;} /*定義起始幀樣式,0%可以換成from*/  
  4.     25%  {background:yellowleft:200pxtop:0px;}   
  5.     50%  {background:blueleft:200pxtop:200px;}   
  6.     75%  {background:greenleft:0pxtop:200px;}   
  7.     100% {background:redleft:0pxtop:0px;} /*定義結(jié)束幀樣式,100%可以換成to*/  
  8.     }   
  9.   

@keyframes定義好了,要使其能發(fā)揮效果,必須通過animation把它綁定到一個選擇器,否則動畫不會有任何效果。下面列出了animation的屬性:

下面設(shè)置上述的所有屬性

CSS Code復(fù)制內(nèi)容到剪貼板
  1. animation-name:myfirst;   
  2. animation-duration:5s;   
  3. animation-timing-function:linear;   
  4. animation-delay:1s;   
  5. animation-iteration-count:infinite;   
  6. animation-direction:alternate;   
  7. animation-play-state:running;   
  8.   

上述所有代碼可以如下簡寫:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. animation:myfirst 5s linear 2s infinite alternate;   
  2. animation-play-state:running;   
  3.   

瀏覽器兼容性

Internet Explorer 10、Firefox 以及 Opera 支持 @keyframes 規(guī)則和 animation 屬性。

Chrome 和 Safari 需要前綴 -webkit-。

注意:Internet Explorer 9,以及更早的版本,不支持 @keyframe 規(guī)則或 animation 屬性。

下面給出上面介紹的關(guān)于keyframes和animation屬性的完整代碼示例:

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>animation演示</title>  
  6.     <style>    
  7.     div   
  8.     {   
  9.     width:100px;   
  10.     height:100px;   
  11.     background:red;   
  12.     position:relative;   
  13.     animation-name:myfirst;   
  14.     animation-duration:5s;   
  15.     animation-timing-function:linear;   
  16.     animation-delay:1s;   
  17.     animation-iteration-count:infinite;   
  18.     animation-direction:alternate;   
  19.     animation-play-state:running;   
  20.     /* Safari and Chrome: */   
  21.     -webkit-animation-name:myfirst;   
  22.     -webkit-animation-duration:5s;   
  23.     -webkit-animation-timing-function:linear;   
  24.     -webkit-animation-delay:1s;   
  25.     -webkit-animation-iteration-count:infinite;   
  26.     -webkit-animation-direction:alternate;   
  27.     -webkit-animation-play-state:running;   
  28.     }   
  29.   
  30.     @keyframes myfirst /*定義動畫名*/   
  31.     {   
  32.     0%   {background:red; left:0px; top:0px;} /*定義起始幀樣式,0%相當(dāng)于from*/   
  33.     25%  {background:yellow; left:200px; top:0px;}   
  34.     50%  {background:blue; left:200px; top:200px;}   
  35.     75%  {background:green; left:0px; top:200px;}   
  36.     100% {background:red; left:0px; top:0px;} /*定義結(jié)束幀樣式,100%相當(dāng)于to*/   
  37.     }   
  38.   
  39.     @-webkit-keyframes myfirst /* Safari and Chrome */   
  40.     {   
  41.     0%   {background:red; left:0px; top:0px;}   
  42.     25%  {background:yellow; left:200px; top:0px;}   
  43.     50%  {background:blue; left:200px; top:200px;}   
  44.     75%  {background:green; left:0px; top:200px;}   
  45.     100% {background:red; left:0px; top:0px;}   
  46.     }   
  47.     </style>  
  48. </head>  
  49. <body>  
  50.     <p>該實例在 Internet Explorer 9 及更早 IE 版本是無效的。</p>  
  51.     <div></div>  
  52. </body>  
  53. </html>  

上面代碼演示了一個正方形沿著一個正方形軌跡運動,基數(shù)次按正方向運動,偶數(shù)次按反方向運動,運動過程中還帶有顏色變化。具體效果,讀者可以自行運行代碼觀察。

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

相關(guān)文章

  • CSS3動畫之利用requestAnimationFrame觸發(fā)重新播放功能

    這篇文章主要介紹了利用requestAnimationFrame重新播放(觸發(fā))CSS3動畫,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-09-11
  • CSS3 animation – steps 函數(shù)詳解

    本文通過實例代碼給大家介紹了CSS3 animation – steps 函數(shù),代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2019-08-30
  • css3中用animation的steps屬性制作幀動畫

    這篇文章主要介紹了css中用animation的steps屬性制作幀動畫,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-25
  • 10分鐘入門CSS3 Animation

    本篇介紹的animation屬性和傳統(tǒng)的動畫制作一樣,能控制幀的每一步,制作出更強大的動畫效果。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看
    2018-12-25
  • css3的動畫特效之動畫序列(animation)

    這篇文章主要介紹了css3的動畫特效之動畫序列(animation) 的相關(guān)資料,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-22
  • CSS3中animation實現(xiàn)流光按鈕效果

    這篇文章主要介紹了CSS3中animation實現(xiàn)流光按鈕效果,本文通過實例代碼給大家介紹的非常詳細(xì)對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-21

最新評論