導讀跟大家講解下有關HTML與CSS中的動畫模塊,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說HTML與CSS中的動畫模塊,小編也收集
跟大家講解下有關HTML與CSS中的動畫模塊,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說HTML與CSS中的動畫模塊,小編也收集到了有關HTML與CSS中的動畫模塊的相關資料,希望大家看到了會喜歡。
這次給大家帶來HTML與CSS中的動畫模塊,使用HTML與CSS中的動畫模塊注意事項有哪些,下面就是實戰案例,一起來看一下。一. 動畫模塊
1.過渡和動畫之間的異同
1.1不同點
過渡必須人為的觸發才會執行動畫 動畫不需要人為的觸發就可以執行動畫
1.2相同點
過渡和動畫都是用來給元素添加動畫的 過渡和動畫都是系統新增的一些屬性 過渡和動畫都需要滿足三要素才會有動畫效果
2 動畫三要素
2.1告訴系統需要執行哪個動畫 2.2告訴系統我們需要自己創建一個名稱叫做lnj的動畫 2.3告訴系統動畫持續的時長
p{ width: 100px; height: 50px; background-color: red; animation-name: lnj; animation-duration: 3s; } @keyframes lnj { from{ margin-left: 0; } to{ margin-left: 500px; } }二.動畫模塊 - 其它屬性 (上)
p { width: 100px; height: 50px; background-color: red; animation-name: sport; animation-duration: 2s; animation-timing-function: linear; animation-iteration-count: 3; //infinite : 無限的 animation-direction: alternate; } @keyframes sport { from{ margin-left: 0; } to{ margin-left: 500px; } } p:hover{ animation-play-state: paused; }三.動畫模塊 - 其它屬性 (下)
.box2{ width: 200px; height: 200px; background-color: blue; margin: 100px auto; animation-name: myRotate; animation-duration: 5s; animation-delay: 2s; animation-fill-mode: both; } @keyframes myRotate { 0%{ transform: rotate(10deg); } 50%{ transform: rotate(50deg); } 100%{ transform: rotate(70deg); } } animation-fill-mode四. 動畫模塊-連寫
1.動畫模塊連寫格式 animation:動畫名稱 動畫時長 動畫運動速度 延遲時間 執行次數 往返動畫;
2.動畫模塊連寫格式的簡寫 animation:動畫名稱 動畫時長;
五. 云層效果
<html lang="en"> <head> <meta charset="UTF-8"> <title>104-動畫模塊-云層效果</title> <style> *{ margin: 0; padding: 0; } ul{ height: 400px; background-color: skyblue; margin-top: 100px; animation: change 5s linear 0s infinite alternate; position: relative; overflow: hidden; //讓屏幕下方的滾動條隱藏掉 } ul li{ list-style: none; width: 400%; //設置li的寬度為屏幕的四倍,移動最多的為屏幕寬度的三倍,為保證屏幕內一直有云朵,故多設置一個屏幕的寬度的云朵 height: 100%; position: absolute; // 設置子絕父相后,三個li會重疊到一起 left: 0; top: 0; } ul li:nth-child(1){ background-image: url("images/cloud_one.png"); animation: one 30s linear 0s infinite alternate; } ul li:nth-child(2){ background-image: url("images/cloud_two.png"); animation: two 30s linear 0s infinite alternate; } ul li:nth-child(3){ background-image: url("images/cloud_three.png"); animation: three 30s linear 0s infinite alternate; } @keyframes change { from{ background-color: skyblue; } to{ background-color: black; } } @keyframes one { from{ margin-left: 0; } to{ margin-left: -100%; //如果先往右移動,又出現屏幕上有一節沒云朵的情況,故先往左移動; } } @keyframes two { from{ margin-left: 0; } to{ margin-left: -200%; //由于動畫的時間都一樣,但是運動的距離不一樣,又由于都是線性速度,所以就會出現有點運動快,有的運動慢! } } @keyframes three { from{ margin-left: 0; } to{ margin-left: -300%; } } </style> </head> <body> <ul> <li></li> <li></li> <li></li> </ul> </body> </html>六. 無限滾動
<html lang="en"> <head> <meta charset="UTF-8"> <title>105-動畫模塊-無限滾動</title> <style> *{ margin: 0; padding: 0; } p{ width: 600px; height: 188px; border: 1px solid #000; margin: 100px auto; overflow: hidden; } ul{ width: 2000px; //這個無限滾動原理就是ul做動畫 height: 188px; background-color: black; //背景顏色黑色,當li的透明度為半透明時,li就會有黑色蒙版效果 animation: move 10s linear 0s infinite normal; //name 時間 速度 延時 無限重復 是否往返(normal代表不往返) } ul li{ float: left; list-style: none; width: 300px; height: 188px; background-color: red; border: 1px solid #000; box-sizing: border-box; } ul:hover{ animation-play-state: paused; } ul:hover li{ opacity: 0.5; //當li的透明度為0.5時,就會看到父元素的背景顏色(黑色),就會有蒙版效果 } ul li:hover{ opacity: 1; //透明度為1,不透明,看不到父元素的背景色,故沒有蒙版效果 } @keyframes move { from{ margin-left: 0; } to{ margin-left: -1200px; //只需要移除屏幕4個li的寬度就可. 屏幕上就會顯示第5.6兩個li,這時,原本的動畫就會恢復的原來的位置接著動畫,實現了無線滾動效果 } } </style> </head> <body> <p> <ul> <li></li> <li></li> <li></li> <li></li> //把前兩個li加在后面,起到過度效果;動畫不會顯得太生硬. <li></li> <li></li> </ul> </p> </body> </html>相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
HTML與CSS中2D轉換模塊
企業開發中使用H5有哪些注意事項
以上就是HTML與CSS中的動畫模塊的詳細內容,更多請關注php中文網其它相關文章!
來源:php中文網