Hover✨ Premium

Magnetic Field

A hundred particles move in a straight line toward a central core that follows the mouse: when a particle reaches it (< 30 px), it respawns at a random position and resumes its path. A field in permanent motion, with no pause or rest state.

JSMagneticParticles

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Hover has 48 effects, including 5 free. Explore the category →

3 usage examples

Hero background — cybersecurity startup — Magnetic Field example 1

① Hero background — cybersecurity startup

WhenThe visitor lands on Cindral's homepage; a hundred green particles (network packets) converge toward the core following their mouse (firewall). They naturally move the cursor while reading, creating a sense of control over threats.
WhyThe effect directly illustrates the product promise — the firewall absorbs threats before they hit their target. The visitor experiences the metaphor before reading the text, making the pitch immediately understandable.
SettingsRoot at position absolute inset:0, transparent background, z-index:1. Field height:360px. Green particles (#22c55e), core in security-green gradient. Text overlay z-index:10 with opaque gradient at top.
AI processing indicator — dashboard card — Magnetic Field example 2

② AI processing indicator — dashboard card

WhenIn the analytics SaaS, a card shows 'AI analysis in progress'. The animated orb (160 × 160 px) replaces the generic spinner: the core stays centred at rest, and particles converge toward it indefinitely with no mouse interaction.
WhyA generic rotating spinner signals waiting without evoking AI processing. The convergence orb illustrates the stream of data being analysed by the model, making the processing state more legible and coherent with the product.
SettingsRoot 160 × 160 px. .mf383-field 160 × 160 px. .mf383-core 28 px (overridden from 60 px). The cursor never enters the field: the core stays centred and particles loop automatically.
Network defence game — Orrath — Magnetic Field example 3

③ Network defence game — Orrath

WhenIn the Orrath mini-game, the player moves the cursor to position their firewall (blue core) and absorb incoming attack packets (orange particles). The mechanic is immediately readable: particles teleport upon reaching the core, simulating neutralisation.
WhyThe effect's physics perfectly match the game mechanic: particles naturally converge toward the core without game code having to drive them. The player just moves the cursor to 'be' the firewall.
SettingsGame area covering the section minus UI bars (top:44px, bottom:50px). Orange particles (#fb923c, 5 × 5 px), blue core (#2563eb). Top bar: logo, score, timer.

How it works

The core (div.mf383-core) is absolutely positioned inside .mf383-field. Its target position is updated on each mousemove (or touchmove) event; on each frame it advances 8% of the remaining gap (lerp with factor 0.08 × f), giving it smooth inertial motion.

The 100 particles (div.mf383-particle) are created at load with random positions and velocities. On every frame, each particle is attracted to the core: vx += (cx − px) × 0.03 × f; vy += (cy − py) × 0.03 × f. Velocities are damped (vx *= 0.95^f). When a particle is within 20 px of the core, it respawns at a random position in the zone. Under reduced motion, particles are arranged in a fixed ring around the centre and do not move.

Accessibility

  • Touch: touchmove moves the core toward the finger. The interaction is identical to the mouse.
  • Keyboard: the effect is purely decorative and does not respond to the keyboard. No information is reserved for the mouse.
  • Reduced motion: under prefers-reduced-motion: reduce, particles are placed in a fixed ring around the centre, visible and readable, with no animation.
  • No ARIA role: .mf383-field has no role. If it illustrates a concept (a logo, a title), add the textual content next to it and aria-hidden="true" on the zone.

Browser compatibility

Pure DOM and CSS, no dependency. IntersectionObserver available since Chrome 51, Firefox 55, Safari 12.1. Physics via requestAnimationFrame normalised to elapsed time. 100 animated divs: measured cost < 1 ms/frame in Chromium on a desktop machine. Not verified on real Safari; expected full.

Chrome 51+✓ Full (measured)
Firefox 55+✓ Full (measured)
Safari 12.1+✓ Expected full (not measured)
Edge 79+✓ Full (measured)
Mobile iOS 12.2+✓ Full on touch (not measured)
Android Chrome 51+✓ Full on touch (not measured)

Without JavaScript, the zone shows only the fixed central core; no particles are created.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0383-root">
  <div class="mf383-field">
    <div class="mf383-core"></div>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Particle count (JS — COUNT constant) 100 50 gives a more airy effect; 200 a dense cloud. Beyond 150, check performance on mobile.
Attraction force (JS — vx += ... * 0.03 * f) 0.03 0.06 pulls particles to the core very fast; 0.01 gives long, elliptical trajectories.
Damping (JS — vx *= Math.pow(0.95, f)) 0.95 0.98 gives higher speeds and a more chaotic orbit; 0.8 makes particles nearly stop and plunge straight back down.
Core size (CSS — .mf383-core { width, height }) 60 px Also adjust the respawn threshold (dist < 20) to half the new radius.
Particle colour (CSS — .mf383-particle { background }) #6366f1 To colour particles individually, assign the colour from JS at creation time.

FAQ

No. Each particle has a random initial velocity; their damping and distance to the core give each one a unique trajectory. Some spiral in wide circles, others dive straight for the core.
The core stays at its last position inside the zone and particles keep orbiting toward it. The effect does not reset when the mouse leaves.
Yes. The core is a div with border-radius: 50%. Remove it for a square, or add an SVG, an image or text inside it. Positioning and motion are handled by JavaScript through left and top properties.