以下三個 Loading 動畫都依靠 CSS3 animation 與 delay 完成,不需要 JavaScript。
使用 ul 與 li 建立多個圓點,再用 ball 與 pulse 兩個元素分別呈現放大與光暈效果。關鍵在於 animation-delay,讓每個圓點依序出現。
.ball { animation: loading 1s linear forwards; }
.pulse { animation: pulse 1s ease-out; }
#layer1 { animation-delay: 0.5s; }
#layer2 { animation-delay: 1s; }
建立一個 100% 寬度的容器,內含 expand 元素,讓寬度從 0 動畫到 100%。
.expand { animation: fullexpand 10s ease-out; }
@keyframes fullexpand {
0% { width: 0; }
100% { width: 100%; }
}
使用多個 bar 元素,透過 opacity 與 animation-delay 讓進度條一格一格亮起。
.bar { opacity: 0; animation: fill 0.5s linear forwards; }
#layerFill1 { animation-delay: 0.5s; }
#layerFill2 { animation-delay: 1s; }
@keyframes fill {
0% { opacity: 0; }
100% { opacity: 1; }
}
這三個範例的共同點是:用 HTML 建立結構,用 CSS 控制時序與外觀,讓載入狀態更生動。