Home >Web Front-end >CSS Tutorial >Creating a Floating Particles Neon Light Effect with HTML, CSS, and JavaScript
In this tutorial, we'll build a captivating neon light effect with floating particles using pure HTML, CSS, and JavaScript. We'll break down each component and explain how they work together to create this stunning visual effect.
Let's start by breaking down the basic HTML structure:
<!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); }
This variable is crucial because:
body { margin: 0; overflow: hidden; background: black; height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center; }
Let's break down each property:
.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; }
Key aspects explained:
.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; }
Gradient analysis:
.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; }
Special effects breakdown:
<!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); }
Animation details:
body { margin: 0; overflow: hidden; background: black; height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center; }
Particle characteristics:
.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; }
Movement breakdown:
.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; }
Function analysis:
.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; }
Responsive considerations:
@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); } }
Optimization strategies:
This effect combines multiple layers of sophistication:
The result is a captivating neon effect that can enhance any web project with minimal performance impact.
The above is the detailed content of Creating a Floating Particles Neon Light Effect with HTML, CSS, and JavaScript. For more information, please follow other related articles on the PHP Chinese website!