CSS3中的動畫效果-------Day72

來源:互聯網
上載者:User

標籤:net   dir   位置   pre   等等   height   相關   學習   距離   

還記得麼,在前面也曾實現過“僅僅用css讓div動起來”,還記得當時是怎麼實現的麼,是的,transition,針對的也比較局限,僅僅有旋轉角度啊,長寬啊之類的,所以說,與其說是動起來,倒真不如說成是過渡。當然它另一個局限性,僅僅有當滑鼠放上後才幹夠觸發,僅僅是一個樣式變成另一個樣式,變化也比較單調,而真正的實現動畫效果,css3中另一個很有效方法:@keyframes。

首先。要知道它的規範和使用方法

還記得transition的使用方法麼:在初始的樣式中增加div{transition:width(height、transform) 5s。width:100px;},然後再div:hover{width:300px},是這樣來實現過渡效果的,那麼動畫又該怎樣呢?

這裡動畫則是先描繪齣動畫的總體效果。然後對於實現動畫的對象進行綁定

這裡用個改動於w3cschool中的範例進行記錄:

@keyframes myfirst{0%   {background: red; left:0px; top:0px;}25%  {background: yellow; left:200px; top:0px;transform:rotate(100deg);}50%  {background: blue; left:200px; top:200px;}75%  {background: green; left:0px; top:200px;}100% {background: red; left:0px; top:0px;}}@-moz-keyframes myfirst /* Firefox */{0%   {background: red; left:0px; top:0px;}25%  {background: yellow; left:200px; top:0px;transform:rotate(100deg);}50%  {background: blue; left:200px; top:200px;}75%  {background: green; left:0px; top:200px;}100% {background: red; left:0px; top:0px;}}@-webkit-keyframes myfirst /* Safari 和 Chrome */{0%   {background: red; left:0px; top:0px;}25%  {background: yellow; left:200px; top:0px;transform:rotate(100deg);}50%  {background: blue; left:200px; top:200px;}75%  {background: green; left:0px; top:200px;}100% {background: red; left:0px; top:0px;}}@-o-keyframes myfirst /* Opera */{0%   {background: red; left:0px; top:0px;}25%  {background: yellow; left:200px; top:0pxl;transform:rotate(100deg);}50%  {background: blue; left:200px; top:200px;}75%  {background: green; left:0px; top:200px;}100% {background: red; left:0px; top:0px;}}

這樣再找一個對象進行綁定。而這個對象你發現一個什麼問題了麼,left和top來描繪距離啊,肯定是絕對位置嘛,所以來寫一下html部分

 <div style="width:100px;height:100px;position:absolute;"></div>
然後進行綁定:

div{animation: myfirst 5s;-moz-animation: myfirst 5s;/* Firefox */-webkit-animation: myfirst 5s;/* Safari 和 Chrome */-o-animation: myfirst 5s;/* Opera */-moz-animation-iteration-count: 4;}
大體的步驟我們這樣就瞭解到了。1:首先確定”動畫效果“已經完畢。2、找到要實現動畫效果的對象;3、將動畫效果和實現的對象進行綁定,如是而已。

可是有一點我們須要注意。並非隨便綁定就能夠實現的,這個綁定是有條件的。那麼是什麼條件呢?

1、確定綁定的是哪一個動畫效果,2、實現動畫效果須要多長時間,假設不寫,默覺得不執行;

當然這是最主要的要求,而我們為了動畫效果實現的更好,還能夠從下面幾個屬性進行設定:

1、animation-iteration-count。設定設定的動畫效果執行的次數,這裡還要明白一點的時,當所有次數執行完後,仍然會消失

2、animation-direction,是動畫效果該怎樣實現,是正常還是逆序;

3、animation-play-state,動畫的執行效果。暫停還是執行;

4、animation-delay,動畫何時開始執行

等等。通過這些屬性。我們能更好的個人化的實現自己的動畫效果了吧


css3在不知不覺中原來已經看了這麼多了。在這個周末應該好好總結一下相關的內容了。這幾天就把還沒看到的幾個地方再學習下好了




CSS3中的動畫效果-------Day72

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.