在本教程中,我們將使用純 HTML、CSS 和 JavaScript 建立帶有浮動粒子的迷人霓虹燈效果。我們將分解每個組件並解釋它們如何協同工作來創造這種令人驚嘆的視覺效果。
讓我們先從分解基本的 HTML 結構開始:
<!DOCTYPE html> <html> <head> <title>Neon Light Effect</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div> <p>Here's what each element does:</p>
First, let's understand our CSS variables:
:root { --blur-size: min(40vw, 40vh); }
這個變數至關重要,因為:
body { margin: 0; overflow: hidden; background: black; height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center; }
讓我們分解每個屬性:
.light-effect { width: var(--blur-size); height: var(--blur-size); position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); filter: blur(calc(var(--blur-size) * 0.25)); animation: pulseNeon 8s ease-in-out infinite; }
關鍵方面解釋:
.light-inner { position: absolute; width: 100%; height: 100%; background: radial-gradient(circle, rgba(138, 43, 226, 0.2) 0%, rgba(72, 61, 139, 0.15) 30%, rgba(0, 0, 255, 0.1) 50%, rgba(255, 255, 255, 0) 70%); mix-blend-mode: screen; }
梯度分析:
.light-outer { position: absolute; width: 100%; height: 100%; background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, rgba(138, 43, 226, 0.1) 40%, rgba(0, 0, 255, 0.05) 60%, rgba(255, 255, 255, 0) 80%); animation: rotateGradient 10s linear infinite; mix-blend-mode: screen; }
特效分解:
<!DOCTYPE html> <html> <head> <title>Neon Light Effect</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div> <p>Here's what each element does:</p>
First, let's understand our CSS variables:
:root { --blur-size: min(40vw, 40vh); }
動畫詳情:
body { margin: 0; overflow: hidden; background: black; height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center; }
顆粒特性:
.light-effect { width: var(--blur-size); height: var(--blur-size); position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); filter: blur(calc(var(--blur-size) * 0.25)); animation: pulseNeon 8s ease-in-out infinite; }
動作分解:
.light-inner { position: absolute; width: 100%; height: 100%; background: radial-gradient(circle, rgba(138, 43, 226, 0.2) 0%, rgba(72, 61, 139, 0.15) 30%, rgba(0, 0, 255, 0.1) 50%, rgba(255, 255, 255, 0) 70%); mix-blend-mode: screen; }
函數分析:
.light-outer { position: absolute; width: 100%; height: 100%; background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, rgba(138, 43, 226, 0.1) 40%, rgba(0, 0, 255, 0.05) 60%, rgba(255, 255, 255, 0) 80%); animation: rotateGradient 10s linear infinite; mix-blend-mode: screen; }
回應注意事項:
@keyframes pulseNeon { 0% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.1); } 100% { transform: translate(-50%, -50%) scale(1); } } @keyframes rotateGradient { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
最佳化策略:
此效果結合了多層複雜性:
結果是迷人的霓虹燈效果,可以增強任何 Web 項目,同時對效能影響最小。
以上是使用 HTML、CSS 和 JavaScript 建立浮動粒子霓虹燈效果的詳細內容。更多資訊請關注PHP中文網其他相關文章!