[HTML/CSS] 超炫Loading動畫
阿新 • • 發佈:2022-05-10
利用到的CSS
1. var 函式
2. calc 函式
Html程式碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>超炫Loading動畫</View Codetitle> <link rel="stylesheet" href="style.css"> </head> <body> <div class="main"> <div class="container"> <div class="circle"> <span style="--i:0;"></span> <span style="--i:1;"></span><span style="--i:2;"></span> <span style="--i:3;"></span> <span style="--i:4;"></span> <span style="--i:5;"></span> <span style="--i:6;"></span> <span style="--i:7;"></span> <span style="--i:8;"></span> <span style="--i:9;"></span> <span style="--i:10;"></span> <span style="--i:11;"></span> <span style="--i:12;"></span> <span style="--i:13;"></span> <span style="--i:14;"></span> <span style="--i:15;"></span> <span style="--i:16;"></span> <span style="--i:17;"></span> <span style="--i:18;"></span> <span style="--i:19;"></span> <span style="--i:20;"></span> </div> <div class="circle"> <span style="--i:0;"></span> <span style="--i:1;"></span> <span style="--i:2;"></span> <span style="--i:3;"></span> <span style="--i:4;"></span> <span style="--i:5;"></span> <span style="--i:6;"></span> <span style="--i:7;"></span> <span style="--i:8;"></span> <span style="--i:9;"></span> <span style="--i:10;"></span> <span style="--i:11;"></span> <span style="--i:12;"></span> <span style="--i:13;"></span> <span style="--i:14;"></span> <span style="--i:15;"></span> <span style="--i:16;"></span> <span style="--i:17;"></span> <span style="--i:18;"></span> <span style="--i:19;"></span> <span style="--i:20;"></span> </div> </div> </div> </body> </html>
CSS程式碼
*{ margin: 0; padding: 0; box-sizing: border-box; } /* 背景 */ .main{ display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: cadetblue; animation: animateColor 8s linear infinite; } /* 背景色變化 */ @keyframes animateColor { 0%{ filter: hue-rotate(0deg); } 100%{ filter: hue-rotate(360deg); } } /* 內容寬 */ .main .container{ display: flex; } /* 盒子-圓 */ .main .container .circle{ position: relative; width: 150px; height: 150px; margin: 0 -8px; } /* 盒子-點 */ .main .container .circle span{ position: absolute; top: 0; right: 0; bottom: 0; left: 0; /* 通過旋轉將 點 畫一個圓 */ transform: rotate( calc( 360deg / 20 * var(--i) )); } /* 每一個點 */ .main .container .circle span::before{ content: ''; position: absolute; right: 0; top: calc( 50% - 7.5px ); width: 15px; height: 15px; background-color: antiquewhite; border-radius: 50%; /* 發光效果 */ box-shadow: 0 0 10px antiquewhite, 0 0 20px antiquewhite, 0 0 40px antiquewhite, 0 0 60px antiquewhite, 0 0 80px antiquewhite, 0 0 100px antiquewhite; /* 通過 大小變化 體現載入 */ transform: scale(0.1); /* 動畫設定 */ animation: animate calc( ( 0.1s * 20 ) * 2 ) linear infinite; animation-delay: calc( 0.1s * var(--i) ); } @keyframes animate { 0%{ transform: scale(1); } 50%,100%{ transform: scale(0.1); } } /* 設定第二個的延遲 和 初始位置 */ .main .container .circle:nth-child(2){ transform: rotate(-180deg); } .main .container .circle:nth-child(2) span::before{ animation-delay: calc( -0.1s * var(--i) ); }View Code