Explosion Radius
The explosion radius determines the distance from your cursor at which particles will be repelled and scatter. It creates an interactive “bubble” around your mouse or finger, making the text responsive to user movement. A larger radius creates dramatic, wide-reaching effects, while a smaller radius requires precise positioning for subtle interactions.
Understanding Explosion Radius
Section titled “Understanding Explosion Radius”The explosion radius is measured in pixels from the cursor position. When your mouse (or finger on touch devices) comes within this distance of a particle, that particle will be pushed away, creating the signature “explosion” effect.
How It Works
Section titled “How It Works”Distance from cursor to particle < explosionRadius → Particle is pushed away
Distance from cursor to particle >= explosionRadius → Particle returns to original positionThe force applied to particles decreases as they get farther from the cursor, creating a natural-looking repulsion effect.
Live Demos
Section titled “Live Demos”Small Explosion Radius
Section titled “Small Explosion Radius”Tight explosion (50px) - particles only react when the mouse is very close, creating precise, subtle interactions.
Small Explosion (50px)
initParticleJS('#canvas', {text: 'SMALL',explosionRadius: { xs: 50, // Small screens: 50px lg: 50 // Large screens: 50px},colors: ['#695aa6']});Try it: Move your mouse over the text. Notice how you need to get very close to the particles to make them scatter.
Medium Explosion Radius
Section titled “Medium Explosion Radius”Standard explosion (150px) - balanced interaction zone that works well for most use cases.
Medium Explosion (150px)
initParticleJS('#canvas', {text: 'MEDIUM',explosionRadius: { xs: 150, lg: 150},colors: ['#FF6B6B']});Try it: The interaction feels natural and easy to trigger without being overwhelming.
Large Explosion Radius
Section titled “Large Explosion Radius”Wide explosion (300px) - particles react from far away, creating dramatic, sweeping effects.
Large Explosion (300px)
initParticleJS('#canvas', {text: 'LARGE',explosionRadius: { xs: 300, lg: 300},colors: ['#E74C3C']});Try it: Just bringing your cursor near the text causes widespread particle movement across the entire composition.
Responsive Explosion Radius
Section titled “Responsive Explosion Radius”Different screen sizes benefit from different explosion radii. Mobile devices typically work better with smaller radii, while large desktop displays can handle dramatic effects.
explosionRadius: {xxxs: 30, // Tiny mobile: 30px (tight, finger-friendly)xxs: 40, // Small mobile: 40pxxs: 50, // Mobile/tablet: 50pxsm: 60, // Tablet: 60pxmd: 70, // Small desktop: 70pxlg: 75, // Desktop: 75pxxl: 80, // Large desktop: 80pxxxl: 90, // Ultra-wide: 90pxxxxl: 100 // 4K+ displays: 100px}This is the default configuration - optimized for all screen sizes.
Mobile-First Approach
Section titled “Mobile-First Approach”// Smaller radii for better mobile UXexplosionRadius: {xxxs: 25, // Very tight on tiny screensxs: 35, // Mobile-optimizedsm: 50, // Tabletlg: 100 // Generous on desktop}Desktop-First Dramatic Effect
Section titled “Desktop-First Dramatic Effect”// Larger radii for dramatic desktop experienceexplosionRadius: {xxxs: 60, // Still functional on mobilexs: 80, // Moderate on mobilelg: 200, // Wide on desktopxl: 250, // Very wide on large screensxxxl: 350 // Dramatic on 4K displays}Dynamic Explosion Radius (Function)
Section titled “Dynamic Explosion Radius (Function)”For advanced control, use a function to calculate the explosion radius dynamically.
// Screen size-based calculationexplosionRadius: function() {const width = window.innerWidth;if (width < 768) { return 40; // Small on mobile} else if (width < 1440) { return 100; // Medium on desktop} else { return 200; // Large on big screens}}
// Percentage of screen widthexplosionRadius: function() {return window.innerWidth * 0.08; // 8% of screen width}
// Time-based animation (pulsing effect)let time = 0;explosionRadius: function() {time += 0.05;return 100 + Math.sin(time) * 30; // Oscillates 70-130px}Choosing the Right Radius
Section titled “Choosing the Right Radius”| Radius Range | Size | Best For | User Experience |
|---|---|---|---|
| 20-50px | Tiny | Mobile devices, precise interactions, subtle effects | Requires direct contact, minimal disturbance |
| 50-100px | Small-Medium | Standard mobile/desktop, balanced interaction | Easy to trigger, not overwhelming |
| 100-200px | Medium-Large | Desktop displays, engaging interactions | Noticeable effect, fun to explore |
| 200-400px | Large | Large screens, artistic projects, hero sections | Dramatic, sweeping movements |
| 400px+ | Extreme | Artistic installations, full-page effects | Particles react across entire viewport |
Use Case Guide
Section titled “Use Case Guide”Professional/Corporate Sites
Section titled “Professional/Corporate Sites”Clean, subtle interactions that don’t distract from content.
{explosionRadius: { xs: 50, // Subtle on mobile lg: 80 // Professional on desktop},colors: ['#2C3E50'],particleRadius: { xs: { base: 1, rand: 1 } }}Why: Maintains professionalism while adding subtle interactivity.
Creative/Portfolio Sites
Section titled “Creative/Portfolio Sites”Engaging, noticeable effects that showcase creativity.
{explosionRadius: { xs: 100, // Engaging on mobile lg: 200 // Dramatic on desktop},colors: [ { color: '#E74C3C', weight: 5 }, { color: '#9B59B6', weight: 2 }],particleRadius: { xs: { base: 2, rand: 2 } }}Why: Creates memorable, interactive experiences that engage visitors.
Hero Sections
Section titled “Hero Sections”Large, attention-grabbing effects for above-the-fold content.
{explosionRadius: { xs: 120, // Strong on mobile lg: 250, // Very dramatic on desktop xxxl: 400 // Extreme on 4K},colors: ['#FF6B6B', '#4ECDC4'],fontSize: 150}Why: Immediately captures attention and encourages interaction.
Touch Devices
Section titled “Touch Devices”Optimized for finger-based interaction rather than precise mouse control.
{explosionRadius: { xxxs: 60, // Larger for finger touch xs: 70, // Easier to trigger sm: 80, // Tablet-optimized lg: 100 // Desktop can be smaller}}Why: Fingers are less precise than mouse cursors - larger radii compensate.
Performance Considerations
Section titled “Performance Considerations”Explosion radius has minimal performance impact. The calculation is simple distance-based math that modern browsers handle efficiently.
However, consider these factors:
Large Radii + Dense Particles
Section titled “Large Radii + Dense Particles”// Potentially slower (many particles affected){explosionRadius: { lg: 400 }, // Very largeparticleRadius: { xs: { base: 1, rand: 0.5 } }, // Many particlesmaxParticles: 10000 // High particle count}
// Optimized version{explosionRadius: { lg: 400 }, // Keep large radiusparticleRadius: { xs: { base: 2, rand: 1 } }, // Slightly largermaxParticles: 3000 // Reasonable limit}Tip: If you have very dense particles (small radius), consider limiting maxParticles when using large explosion radii.
Interaction Patterns
Section titled “Interaction Patterns”Standard Interaction (Recommended)
Section titled “Standard Interaction (Recommended)”{explosionRadius: { xs: 50, lg: 100 },trackCursorOnlyInsideCanvas: false // Track anywhere (default)}Particles respond to cursor position anywhere on the page for fluid interaction.
Bounded Interaction
Section titled “Bounded Interaction”{explosionRadius: { xs: 50, lg: 100 },trackCursorOnlyInsideCanvas: true // Only track inside canvas}Particles only respond when cursor is directly over the canvas. Useful for:
- Multiple canvases on the same page
- Clear interaction boundaries
- Preventing cross-canvas interference
Advanced Techniques
Section titled “Advanced Techniques”Proximity-Based Color Shifting
Section titled “Proximity-Based Color Shifting”Combine explosion radius with weighted colors for dynamic effects:
{explosionRadius: { lg: 200 },colors: [ { color: '#3498DB', weight: 8 }, // Mostly blue at rest { color: '#E74C3C', weight: 2 } // Some red when disturbed]}The red particles become more noticeable when scattered by the explosion.
Variable Radius Based on Scroll Position
Section titled “Variable Radius Based on Scroll Position”let scrollPercent = 0;
window.addEventListener('scroll', () => {scrollPercent = window.scrollY / (document.body.scrollHeight - window.innerHeight);});
explosionRadius: function() {// Radius grows as user scrolls downreturn 50 + (scrollPercent * 150); // 50px → 200px}Asymmetric Explosion (Directional Push)
Section titled “Asymmetric Explosion (Directional Push)”While not built-in, you could modify the particle behavior to push particles in specific directions rather than radially outward.
Common Patterns
Section titled “Common Patterns”Minimal Disturbance
Section titled “Minimal Disturbance”{explosionRadius: { xs: 40, lg: 60 },friction: { base: 0.95, rand: 0.03 } // High friction = slow return}Small radius + high friction = gentle, slowly-recovering movement.
Energetic Bouncing
Section titled “Energetic Bouncing”{explosionRadius: { xs: 100, lg: 200 },friction: { base: 0.75, rand: 0.05 } // Low friction = bouncy}Large radius + low friction = particles spring back vigorously.
Smooth Wave Effect
Section titled “Smooth Wave Effect”{explosionRadius: { xs: 150, lg: 250 },friction: { base: 0.88, rand: 0.05 },particleRadius: { xs: { base: 2, rand: 1 } }}Medium-large radius with balanced friction creates smooth wave-like motion.
Best Practices
Section titled “Best Practices”- Test on target devices: Mobile users need different radii than desktop users
- Match your content: Large hero text can handle larger radii; body text should be subtle
- Consider friction: Low friction + large radius = chaotic; high friction + small radius = subtle
- Responsive is key: Always define at least
xsandlgbreakpoints - Don’t overdo it: Radii over 500px are rarely practical
- Touch-friendly: Add 20-30px extra for touch devices vs. mouse
- Test performance: On older devices, keep radii under 200px with
maxParticles< 5000
Troubleshooting
Section titled “Troubleshooting”Particles react from too far away?
- Decrease
explosionRadiusvalues - Try:
{ xs: 40, lg: 60 }
Need to get too close to trigger effect?
- Increase
explosionRadiusvalues - Try:
{ xs: 100, lg: 150 }
Effect feels different on mobile vs desktop?
- Set explicit breakpoint values
- Test on actual devices, not just browser resize
Particles don’t return to position smoothly?
- This is a
frictionissue, not explosion radius - See Friction Effects
Multiple canvases interfering with each other?
- Set
trackCursorOnlyInsideCanvas: true - See Configuration Reference
Performance issues with large radius?
- Check particle count with
maxParticles - Consider slightly larger
particleRadiusto reduce total count - Enable
supportSlowBrowsers: true
Accessibility Considerations
Section titled “Accessibility Considerations”- Reduced motion: The library respects
prefers-reduced-motionCSS media query - Touch targets: Ensure explosion radius on mobile is at least 40px for easy triggering
- Keyboard navigation: Explosion effects are mouse/touch only - ensure your text is still readable
- Screen readers: Text content should be available in the
textordata-textattribute
Related Examples
Section titled “Related Examples”- Explosion Radius (API Reference) - Full configuration options
- Particle Density - Control particle size and detail
- Friction Effects - How particles return to position
- Cursor Tracking - Control where particles react
- Performance Optimization - Optimize large installations