如何用纯 CSS 创作一个精彩的彩虹 loading 特效
生活随笔
收集整理的這篇文章主要介紹了
如何用纯 CSS 创作一个精彩的彩虹 loading 特效
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
效果預覽
在線演示
按下右側的“點擊預覽”按鈕可以在當前頁面預覽,點擊鏈接可以全屏預覽。
https://codepen.io/comehope/pen/vjvoow
可交互視頻教程
此視頻是可以交互的,你可以隨時暫停視頻,編輯視頻中的代碼。
請用 chrome, safari, edge 打開觀看。
https://scrimba.com/p/pEgDAM/cPLGLhV
源代碼下載
本地下載
每日前端實戰系列的全部源代碼請從 github 下載:
https://github.com/comehope/front-end-daily-challenges
代碼解讀
定義 dom:
<div class="rainbow"><div class="bows"><span></span><span></span><span></span><span></span><span></span><span></span></div> </div>居中顯示:
html, body, .bows {height: 100%;display: flex;align-items: center;justify-content: center;background: black; }定義彩虹的尺寸:
.rainbow {width: 20em;height: 10em; }定義彩虹內拱形的尺寸:
.bows {width: 100%;height: 200%;position: relative; }定義彩虹內所有拱形共有的特性:
.bows {transform: rotate(225deg); }.bows span {position: absolute;width: calc(100% - 2em * (var(--n) - 1));height: calc(100% - 2em * (var(--n) - 1));border: 1em solid var(--color);box-sizing: border-box;border-top-color: transparent;border-left-color: transparent;border-radius: 50%; }分別設置每個拱形的個性變量:
.bows span:nth-child(1) {--n: 1;--color: orangered; }.bows span:nth-child(2) {--n: 2;--color: orange; }.bows span:nth-child(3) {--n: 3;--color: yellow; }.bows span:nth-child(4) {--n: 4;--color: mediumspringgreen; }.bows span:nth-child(5) {--n: 5;--color: deepskyblue; }.bows span:nth-child(6) {--n: 6;--color: mediumpurple; }定義動畫效果:
.bows span {animation: rotating 3s infinite;animation-delay: calc(0.05s * var(--n)); }@keyframes rotating {0%, 20% {transform: rotate(0deg);}80%, 100% {transform: rotate(360deg);} }最后,隱藏掉容器之外的內容:
.rainbow {overflow: hidden; }大功告成!
原文地址:https://segmentfault.com/a/1190000014939781
總結
以上是生活随笔為你收集整理的如何用纯 CSS 创作一个精彩的彩虹 loading 特效的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 理解 async/await 的执行
- 下一篇: MySQL每秒57万的写入,带你飞~