參考:https://www.qianduan.net/css3-animation/ css
常見用法:css3
:hover{ animation:mymove 4s ease-out 1s backwards;}
@-webkit-keyframes mymove /*Safari and Chrome*/ { from {left:0px;} to {left:200px;} }
解釋:
mymove :keyframes的名稱;
4s:動畫的總時間;
ease-out: 快結束的時候慢下來;
1s:停頓1秒後開始動畫;
backwards:動畫結束後回到原點
默認:播放一次
或者
transition:left 4s ease-out :hover{left:200px}
兼容主流瀏覽器:web
.test{ -webkit-animation: < 各類屬性值 >; -moz-animation: < 各類屬性值 >; -o-animation: < 各類屬性值 >; animation: < 各類屬性值 >; }
animation-name,規定要綁定的keyframes
的名稱,隨便你取,不過爲了往後維護的方便,建議取一個跟動做相關名稱相近的名稱比較好。好比要咱們要綁定一個跑的動做,那麼能夠命名爲run。瀏覽器
time,這裏有兩個時間,前面一個是規定完成這個動畫所須要的時間,全稱叫animation-duration
,第二個time爲動畫延遲開始播放的時間,全稱叫animation-delay
,這兩個數值能夠用秒’s’也能夠用微秒’ms’來寫,1000ms=1s,這個不用一一介紹。post
animation-timing-function,規定動畫的運動曲線,這裏有9個值,分別是ease
| linear
| ease-in
| ease-out
| ease-in-out
| step-start
| step-end
| steps
([, [ start
| end
] ]?) | cubic-bezier(x1, y1, x2, y2)
動畫
ease
:動畫緩慢開始,接着加速,最後減慢,默認值;linear
:動畫從頭至尾的速度是相同的;ease-in
:以低速開始;ease-out
:以低速結束;ease-in-out
:動畫以低速開始和結束;
效果同樣 (按步數)steps
.test1{ background:url(http://img.xiaoho.com/2014/12/test.png) no-repeat 0 0; -webkit-animation:run 350ms steps(1) infinite 0s;} @-webkit-keyframes run { 0% { background-position:0; } 20% { background-position:-90px 0; } 40% { background-position:-180px 0; } 60% { background-position:-270px 0; } 80% { background-position:-360px 0; } 100% { background-position:-450px 0; } } .test2{ background:url(http://img.xiaoho.com/2014/12/test.png) no-repeat 0 0; -webkit-animation:run 350ms steps(5) infinite 0s;} @-webkit-keyframes run { 100% { background-position:-450px 0; } }
animation-iteration-count,動畫播放次數,默認值爲1,infinite
爲無限制,假如設置爲無限制,那麼動畫就會不停地播放。 url
normal
| reverse
| alternate
| alternate-reverse
reverse
爲反向轉動,alternate一開始正常轉動,播放完一次以後接着再反向轉動,假如設置animation-iteration-count:1
則該值無效,alternate-reverse
一開始爲反向轉動,播完一次以後按照迴歸正常轉動,交替轉動,設置count
爲1,則該值無效。running
和paused
。默認值爲normal
,動畫正常播放。假如是爲paused
,那麼動畫暫停。假如一個動畫一開始爲運動,那麼假如設置paused
那麼該動畫暫停,假如再設置running
,那麼該動畫會從剛纔暫停處開始運動animation-fill-mode
: none
| forwards
| backwards
| both
; none
,播放完以後不改變默認行爲,默認值,forwards
則是停在動畫最後的的那個畫面,backwards
則是回調到動畫最開始出現的畫面,both
則應用爲動畫結束或開始的狀態