CSS3動畫功能,css3動畫

來源:互聯網
上載者:User

CSS3動畫功能,css3動畫
1.transition功能

transition屬性的使用方法:transition:property duration timing-function;

其中property表示對哪個屬性進行平滑過渡,duration表示多長時間完成屬性值的平滑過渡,timing-function表示通過什麼方法來進行平滑過渡。

多平滑過渡樣本:

 1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4     <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5     <meta http-equiv="x-ua-compatible" content="IE=edge"> 6     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 7     <title>測試</title> 8 </head> 9 <body>10 <div id="test"></div>11 <style>12     #test{13         width: 500px;14         height: 500px;15         background-color: yellow;16         /*css動畫*/17         transform: rotate(0);18         -webkit-transition: transform 0.5s linear, width 0.5s linear;19         -moz-transition: transform 0.5s linear, width 0.5s linear;20         -ms-transition: transform 0.5s linear, width 0.5s linear;21         -o-transition: transform 0.5s linear, width 0.5s linear;22         transition: transform 0.5s linear, width 0.5s linear;23     }24     #test:hover{25         width: 200px;26         transform: rotate(180deg);27     }28 </style>29 </body>30 </html>
2.animation功能

使用樣本:

 1 <!DOCTYPE html> 2 <html lang="zh-CN"> 3 <head> 4     <meta http-equiv="content-type" content="text/html; charset=utf-8"> 5     <meta http-equiv="x-ua-compatible" content="IE=edge"> 6     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 7     <title>測試</title> 8 </head> 9 <body>10 <div id="test"></div>11 <style>12 /*animation動畫*/13     @-webkit-keyframes colorChange {14         0%{15             background-color: deepskyblue;16         }17         50%{18             background-color: red;19         }20         100%{21             background-color: deepskyblue;22         }23     }24     #test{25         width:500px;26         height: 500px;27         background-color: deepskyblue;28     }29     #test:hover{30         animation-name: colorChange;31         animation-duration: 1s;32         animation-timing-function: linear;33     }34 </style>35 </body>36 </html>

實現動畫的方法:

方法 屬性值的變化速度
linear 在動畫開始時與結束時以同樣的速度進行變化
ease-in 動畫開始時速度很慢,然後速度沿曲線值進行加快
ease-out 動畫開始時速度很快,然後速度沿曲線值進行放慢
ease 動畫開始時速度很慢,然後速度沿曲線值進行加快,然後再沿曲線值進行放慢
ease-in-out 動畫開始時速度很慢,然後速度沿曲線值進行加快,然後再沿曲線值進行放慢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.