您好,登錄后才能下訂單哦!
這篇文章主要介紹CSS中loading效果之吃豆人的實現方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
HTML布局
<div class="container"> <div class="loading"> <div class="eat"></div> <div class="load"></div> <div class="load"></div> <div class="load"></div> </div> </div>
CSS 樣式
主要使用了動畫效果,通過不斷控制元素的角度位置實現一個類似于吃豆人一樣的loading demo。
body { margin: 0; padding: 0; background: #fff; } .container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } .loading { position: relative; width: 200px; height: 50px; display: flex; } .eat { position: relative; width: 50px; height: 50px; left: 0; color: #ff0000; animation: eat-animate 2.4s ease-in-out infinite; } @keyframes eat-animate { 100% { left: 150px; } } .eat::before { content: ''; position: absolute; width: 0; height: 0; width: 50px; height: 25px; top: 0; border-radius: 50px 50px 0 0; background: currentColor; transform: rotate(-30deg); animation: eat-top 2.4s ease-in-out infinite; } @keyframes eat-top { 20% { transform: rotate(-30deg); } 35% { transform: rotate(0deg); } 45% { transform: rotate(-30deg); } 60% { transform: rotate(0deg); } 70% { transform: rotate(-30deg); } 85% { transform: rotate(0deg); } 100% { transform: rotate(0deg); } } .eat::after { content: ''; position: absolute; width: 0; height: 0; width: 50px; height: 25px; bottom: 0; border-radius: 0 0 50px 50px; background: currentColor; transform: rotate(30deg); animation: eat-bottom 2.4s ease-in-out infinite; } @keyframes eat-bottom { 20% { transform: rotate(30deg); } 35% { transform: rotate(0deg); } 45% { transform: rotate(30deg); } 60% { transform: rotate(0deg); } 70% { transform: rotate(30deg); } 85% { transform: rotate(0deg); } 100% { transform: rotate(0deg); } } .load { position: relative; width:30px; height: 30px; margin: 10px; color: #e47272; border-radius: 50%; background: currentColor; } .load:nth-child(2) { animation: load1 2.4s linear infinite; transform: scale(1); } @keyframes load1 { 35% { transform: scale(0); } 100% { transform: scale(0); } } .load:nth-child(3) { animation: load2 2.4s linear infinite; transform: scale(1); } @keyframes load2 { 30% { transform: scale(1); } 58% { transform: scale(0); } 100% { transform: scale(0); } } .load:nth-child(4) { animation: load3 2.4s linear infinite; transform: scale(1); } @keyframes load3 { 60% { transform: scale(1); } 80% { transform: scale(0); } 100% { transform: scale(0); } }
Preview
以上是“CSS中loading效果之吃豆人的實現方法”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。