Spring Cursor Mesh

A lattice of points that spring back to rest, part around the pointer, and carry a click as a ring across the grid.


Spring Cursor Mesh


A spring cursor mesh is a grid that behaves like cloth. Every intersection has a home. The pointer pushes nearby points away. A click sends a ring through the lattice. Each point is always trying to get home, and a damper keeps that return from oscillating. The motion is one requestAnimationFrame loop. There is no CSS transition on the points, because a transition cannot follow a moving target every frame.

This is the interactive cousin of the spotlight card and the particle cursor trail. Those decorate the pointer. The mesh is a surface the pointer presses into.

The integrator

A spring needs a position, a velocity, a target, a stiffness, and a damping. Semi-implicit Euler is enough, and it stays stable if you clamp the frame delta.

function spring(value, velocity, target, stiffness, damping, dt) {
  const acc = (target - value) * stiffness - velocity * damping;
  velocity += acc * dt;
  value += velocity * dt;
  return [value, velocity];
}

dt is seconds, capped at about 0.032 so a stalled tab does not fling the grid. Stiffness 62 and damping 15 is slightly under critical (2 * Math.sqrt(62) is about 15.7). The points arrive and stop. They do not bounce. That is the difference between a cloth and a jelly.

Each point stores x, y, vx, vy, and a home hx, hy. The home is recomputed on resize. The spring chases a target that is the home plus whatever the pointer and the impulses are doing this frame.

Cursor falloff and the click ring

Influence is 1 - distance / 200, squared, so the push is local and dies before the edge of the reach. The direction is away from the pointer, along the vector from the pointer to the point’s home. Pushing the current position instead of the home makes the grid crawl.

A click pushes an impulse { x, y, age }. The ring is a Gaussian centered on age * 720 pixels. Points near that radius get a radial kick. The kick fades with exp(-age * 1.35). Two clicks can be in flight. Older ones drop off the front of the list after 2.4 seconds.

When the pointer has been gone for about 1.4 seconds, a slow Lissajous point takes its place so the surface is alive in a preview. A real pointermove takes over immediately.

Drawing

One canvas, device pixel ratio capped at 2. Lines connect each point to its right and lower neighbor in a single stroke. A soft radial fill sits under the pointer. The background is #100e0c and the line is a warm bone color at 38% opacity. The grid density is one point about every 54 pixels, so a laptop is a few hundred springs, which is comfortable in one loop.

Accessibility

The canvas has a name. The hint is real text. Under prefers-reduced-motion: reduce, targets are ignored and the grid draws at rest. The information was never in the deformation. If you put a headline over this surface, keep it in HTML on top of the canvas, not painted into the bitmap.

Questions about spring meshes

How do I make a grid follow the cursor with spring physics?

Give every intersection a home and a velocity. Each frame, set a target a short distance away from the pointer, then integrate a damped spring from the current point toward that target. Draw lines between neighbors.

Why does my spring mesh bounce forever?

Damping is too low for the stiffness. Critical damping is about 2 * Math.sqrt(stiffness). Sit on that number or a hair under it. Also cap dt. A single long frame with an uncapped delta reads as an explosion, and the leftover velocity looks like endless bounce.

Can I build this with CSS transitions?

A transition eases toward a value you set once. This target changes every frame, and every point has its own velocity. That is a simulation. CSS can fade the canvas in. It should not move the points.