這篇文章主要介紹使用CSS和混色模式實現(xiàn)loader動畫效果的案例,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
https://github.com/comehope/front-end-daily-challenges
代碼解讀定義 dom,只有 1 個元素:
<div class="loader"></div>
居中顯示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: lightyellow; }
定義容器尺寸:
.loader { width: 30em; height: 3em; font-size: 10px; }
用偽元素畫出2個圓角矩形,各占容器的一半寬,放置在容器的左右兩端,分別上色:
.loader { position: relative; } .loader::before, .loader::after { content: ''; position: absolute; width: 50%; height: inherit; border-radius: 1em; } .loader::before { left: 0; background-color: dodgerblue; } .loader::after { right: 0; background-color: hotpink; }
為圓角矩形增加 'loading' 文本:
.loader::before, .loader::after { content: 'loading'; font-size: 2.5em; color: white; text-align: center; line-height: 1em; }
增加動畫效果:
.loader::before, .loader::after { animation: 5s move ease-in-out infinite; } @keyframes move { 50% { transform: translateX(100%); } }
為兩個圓角矩形分別設(shè)置運動方向變量,使它們相對移動:
.loader::before { --direction: 1; } .loader::after { --direction: -1; } @keyframes move { 50% { transform: translateX(calc(100% * var(--direction))); } }
最后,設(shè)置混色模式,使兩個矩形相交的部分不是覆蓋而是使顏色重疊:
.loader::before, .loader::after { mix-blend-mode: multiply; }
大功告成!
以上是使用CSS和混色模式實現(xiàn)loader動畫效果的案例的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道!
網(wǎng)站題目:使用CSS和混色模式實現(xiàn)loader動畫效果的案例-創(chuàng)新互聯(lián)
文章鏈接:http://chinadenli.net/article22/hdejc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計公司、電子商務(wù)、移動網(wǎng)站建設(shè)、軟件開發(fā)、定制開發(fā)、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容