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

CSS的animation屬性使用實(shí)例講解

  發(fā)布時(shí)間:2015-09-07 17:16:46   作者:佚名   我要評(píng)論
這篇文章主要介紹了CSS的animation屬性使用實(shí)例講解,是CSS入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下

一、animation的語(yǔ)法
 
1、@keyframes——插入關(guān)鍵幀
 
(1)FormTo形式:

CSS Code復(fù)制內(nèi)容到剪貼板
  1. @keyframes demo {   
  2.      from {   
  3.        Properties:Properties value;   
  4.      }   
  5.      Percentage {   
  6.        Properties:Properties value;   
  7.      }   
  8.      to {   
  9.        Properties:Properties value;   
  10.      }   
  11. }  

 
 
(2)百分比的形式:
 

CSS Code復(fù)制內(nèi)容到剪貼板
  1. @keyframes demo {   
  2.       0% {   
  3.          Properties:Properties value;   
  4.       }   
  5.       Percentage {   
  6.          Properties:Properties value;   
  7.       }   
  8.       100% {   
  9.          Properties:Properties value;   
  10.       }   
  11. }  

 
 
2、animation-name——定義動(dòng)畫的名稱

animation-name: none | “動(dòng)畫的名稱”;
 
 
(1)動(dòng)畫的名稱是由Keyframes創(chuàng)建的動(dòng)畫名,這里必須和創(chuàng)建的動(dòng)畫名保持一致。如果不一致,將不能實(shí)現(xiàn)任何動(dòng)畫效果
(2)none為默認(rèn)值,當(dāng)值為none時(shí),將沒有任何動(dòng)畫效果
 
3、animation-duration
 
animation-duration: time (s)
 
 
animation-duration是指定元素播放動(dòng)畫所持續(xù)的時(shí)間,取值為數(shù)值,單位為秒(s),其默認(rèn)值為“0”。
 
4、animation-timing-function
 
animation-timing-function:ease(緩沖) || ease-in(加速) || ease-out(減速) || ease-in-out(先加速后減速) || linear(勻速) || cubic-bezier(自定義一個(gè)時(shí)間曲線)
 
 
animation-timing-function是用來(lái)指定動(dòng)畫的播放方式,具有以下六種變換方式:ease(緩沖);ease-in(加速);ease-out(減速);ease-in-out(先加速后減速);linear(勻速);cubic-bezier(自定義一個(gè)時(shí)間曲線)。
 
5、animation-delay
 
animation-delay: time(s)
 
 
animation-delay:是用來(lái)指定元素動(dòng)畫開始時(shí)間。取值為數(shù)值,單位為秒(s),其默認(rèn)值為“0”。這個(gè)屬性和animation-duration使用方法是一樣的。
 
6、animation-iteration-count
 
animation-iteration-count:infinite || number
 
animation-iteration-count是指定元素播放動(dòng)畫的循環(huán)次數(shù),其取值為數(shù)字,默認(rèn)值為“1”或者infinite(無(wú)限次數(shù)循環(huán))。
 
7、animation-direction
 
animation-direction: normal || alternate
 
animation-direction是指定元素動(dòng)畫播放的方向,如果是normal,那么動(dòng)畫的每次循環(huán)都是向前播放;如果是alternate,那么動(dòng)畫播放在第偶數(shù)次向前播放,第奇數(shù)次向反方向播放。
 
8、animation-play-state

animation-play-state:running || paused
 
 
animation-play-state主要是用來(lái)控制元素動(dòng)畫的播放狀態(tài)。其主要有兩個(gè)值,running和paused,其中running為默認(rèn)值。這個(gè)屬性目前很少內(nèi)核支持,所以只是稍微提一下。

二、animation事件接口
其實(shí)目前基本的就是三個(gè)事件而已:開始、迭代、結(jié)束。開始和結(jié)束都知道是什么意思。至于這個(gè)迭代,由于animation中有個(gè)iteration-count屬性,它可以定義動(dòng)畫重復(fù)的次數(shù),因此動(dòng)畫會(huì)有許多次開始和結(jié)束。但是真正的“開始”和“結(jié)束”事件是關(guān)于整個(gè)動(dòng)畫的,他們只會(huì)觸發(fā)一次,而中間由于重復(fù)動(dòng)畫引起的“結(jié)束并開始下一次”將觸發(fā)整個(gè)“迭代”事件。
  這三個(gè)事件的標(biāo)準(zhǔn)名稱是:
    開始:animationstart
    迭代:animationiteration
    結(jié)束:animationend
  但是目前版本的Chrome需要加上webkit前綴,而且還要注意大小寫
    開始:webkitAnimationStart
    迭代:webkitAnimationIteration
    結(jié)束:webkitAnimationEnd
  最后是實(shí)例代碼和截圖

CSS Code復(fù)制內(nèi)容到剪貼板
  1. <style>   
  2. @-webkit-keyframes test {   
  3.   0% {background:red;}   
  4.   25% {background:green;}   
  5.   50% {background:blue;}   
  6.   100% {background:red;}   
  7. }   
  8. @keyframes test {   
  9.   0% {background:red;}   
  10.   25% {background:green;}   
  11.   50% {background:blue;}   
  12.   100% {background:red;}   
  13. }   
  14. </style>   
  15. <script>   
  16. onload=function(){   
  17.   var html=document.documentElement;   
  18.   //定義事件回調(diào)函數(shù)   
  19.   var start=function(){   
  20.     console.log("start");   
  21.   },iteration=function(e){   
  22.     console.log(e);   
  23.   },end=function(){   
  24.     console.log("end");   
  25.   };   
  26.   //綁定事件   
  27.   html.addEventListener("webkitAnimationIteration",iteration);   
  28.   html.addEventListener("animationiteration",iteration);   
  29.   html.addEventListener("webkitAnimationStart",start);   
  30.   html.addEventListener("animationstart",start);   
  31.   html.addEventListener("webkitAnimationEnd",end);   
  32.   html.addEventListener("animationend",end);   
  33.   //開始執(zhí)行動(dòng)畫   
  34.   html.style.animation=   
  35.   html.style.WebkitAnimation=   
  36.   "test 1s linear 0s 3";   
  37. };   
  38. </script>  

相關(guān)文章

最新評(píng)論