Particle animations have become a signature element of Nebula’s visual language. They create a sense of depth, motion, and interactivity that aligns perfectly with a futuristic brand identity. This guide walks you through the process of building lightweight, responsive particle backgrounds using modern JavaScript libraries.
Why Use Particles?
Particles simulate stars, dust, or digital glitches, turning a static page into an immersive experience. When used sparingly, they:
- Increase dwell time by up to 18%.
- Provide subtle visual cues that guide user navigation.
- Reinforce a high‑tech brand personality.
Choosing the Right Library
There are several options, but Nebula prefers tsParticles because of its modular architecture, TypeScript support, and built‑in performance optimizations.
Installation
npm install tsparticles
Basic Configuration
Below is a minimal setup that creates a dark background with glowing purple particles that follow the cursor.
import { loadFull } from "tsparticles";
import { tsParticles } from "tsparticles-engine";
async function initParticles() {
await loadFull(tsParticles);
await tsParticles.load("tsparticles", {
background: { color: { value: "hsl(220,15%,10%)" } },
particles: {
number: { value: 80 },
color: { value: "hsl(260,80%,60%)" },
shape: { type: "circle" },
opacity: { value: 0.7 },
size: { value: { min: 2, max: 4 } },
move: { enable: true, speed: 1, direction: "none", outModes: { default: "bounce" } },
links: { enable: true, distance: 150, color: "hsl(260,80%,60%)", opacity: 0.5, width: 1 }
},
interactivity: {
events: { onHover: { enable: true, mode: "repulse" } },
modes: { repulse: { distance: 100 } }
}
});
}
initParticles();
Performance Best Practices
To keep the animation smooth on mobile devices:
- Limit particle count to under 100 for small screens.
- Use
requestAnimationFramefor custom effects. - Pause the animation when the tab is hidden (visibility API).
Adding Scroll‑Triggered Effects
Combine particles with scroll libraries like GSAP ScrollTrigger to fade or slide the canvas as the user scrolls.
gsap.to("#tsparticles", { opacity: 0, scrollTrigger: { start: "top top", end: "bottom top", scrub: true } });
Real World Example: Nebula Hero Section
Our hero area features a starfield that reacts to mouse movement, paired with a headline that slides in from the left. The result is a captivating first impression that aligns with the agency’s futuristic ethos.
Conclusion
Particle backgrounds, when implemented thoughtfully, add a layer of interactivity that can set your site apart. Follow the steps above, keep performance in mind, and let Nebula’s design tokens guide the color choices for a cohesive look.