10純 CSS 創作一個同心圓弧旋轉 loader 特效
阿新 • • 發佈:2018-12-18
原文地址:https://segmentfault.com/a/1190000014682999
想到了扇形:正方形 -》border-radius: 50%; -》取四份中的任意一份。
不過如何取任意相關圓心角的扇形呢?
HTML程式碼:
<div class="circle"></div>
CSS程式碼:
html, body,.circle { margin: 0; padding: 0; height: 100%; display:flex; justify-content: center; align-items: center; } /* 優化程式碼 減少程式碼重複 */ .circle, .circle::before, .circle::after { border-width: 0.4em; border-style: solid; border-radius: 50%; /* 使左右透明 ,只剩上下弧 如何任意該弧所佔圓心角呢? */ border-left-color: transparent; border-right-color: transparent; /* 動畫名稱 週期 節奏 迴圈次數 是否反向播放*/ animation: animate 4s ease-in-out infinite alternate; } .circle{ width:10em; height: 10em; border-top-color: red; border-bottom-color: blue; font-size: 20px; /* 定位會讓其分離 */ position: relative; } .circle::before, .circle::after { content: ''; position: absolute; } .circle::before { width: 70%; height: 70%; border-top-color: orange; border-bottom-color: cyan; animation-duration: 8s; } .circle::after { width: 40%; height: 40%; border-top-color: yellow; border-bottom-color: limegreen; animation-duration: 16s; } @keyframes animate { from { transform: rotate(0deg); } to { transform: rotate(1440deg); } }