代碼來自頭條號"前端小智", 侵權刪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>Document</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body{ width: 100%; height: 100vh; background-color: #000; display: flex; justify-content: center; align-items: center; } .loader{ position: relative; } span{ position: absolute; width: 40px; height: 40px; display: block; animation: animate 4s linear calc(-0.5s*var(--i)) infinite; /* 這個計算我一直沒搞懂 搞懂了在補充吧*/ background-color: #0f0; box-shadow: 0 0 10px #0f0, 0 0 40px #0f0, 0 0 80px #0f0, 0 0 120px #0f0, 0 0 160px #0f0; transform-origin: bottom; } @keyframes animate { 0%{ top: 0; left: 150px; transform: scaleY(1); filter: hue-rotate(0deg);/*給圖像應用色相旋轉 "angle"一值設定圖像會被調整的色環角度值 也不知道色環是哪一個*/ } 2%{ top: 0; left: 150px; transform: scaleY(0.5); /*這塊是作出了彈性效果*/ } 10%{ top: 0; left: 80px; transform: scaleY(1); } 40%{ top: 0; left: -150px; } 60%{ top: -200px; left: -150px; } 85%{ top: -200px; left: 150px; } 100%{ top: 0; filter: hue-rotate(360deg); left: 150px; } } </style> </head> <body> <div class="loader"> <span style="--i:0"></span> <!-- --i:0 這是什麼寫法--> <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> </div> </body> </html>