Magnetic pointer attraction on dock buttons

I wanted to know if one ElementGL WebGL 2 canvas could pull five live drawable HTML dock buttons toward your cursor or finger with directional liquid stretch, glowing field contours behind them, damped elastic recoil past an escape threshold and aligned clicks via updateElementGeometry(). Move or drag across the stage, or tap Hover preset or Auto orbit probe on touch screens.

Select · 0 clicks
Move or drag near dock tiles Escape: 120 px

Starting...

Show the code five drawable dock tiles, spring detachment physics, magnetic flux and liquid-stretch GLSL, geometry sync and 2D fallback
  1. Backdrop and five drawable dock buttons in one canvas. #mf-backdrop hosts the editable mode readout pill and status counter, while #mf-item-0 through #mf-item-4 stay independent drawable buttons.
  2. Damped spring attraction and escape-threshold recoil. Steps each button's displacement toward the pointer inside pullRadius and fires an underdamped elastic snap-back once the pointer crosses the threshold, using explicit tMs timestamps.
  3. Field contours, bending flux lines and liquid edge stretch shader. Pass 0 renders pulsing concentric field contours, curved flux lines toward engaged tiles and rest sockets; Pass 1 elongates each button's leading edge along uPullDir over a 28 px bleed quad.
  4. Per-button hit alignment with updateElementGeometry(). Calibrates geometryUnit() once per size, updates every displaced button's canvasTransform on each move frame and flips dataset.hitTick.
  5. Five-argument drawElementImage() 2D fallback. Draws the backdrop, field rings, curved flux arcs and shifted dock buttons with explicit CSS pixel widths and heights.

How it works

One <canvas id="mf-canvas" content="drawable" layoutsubtree> hosts #mf-backdrop (carrying the editable mode pill and summary readout) plus five separate drawable <button> tiles (#mf-item-0 to #mf-item-4). One ElementGL context from /lib/element-gl.js sets gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) at creation and inside onRestored so rounded borders and anti-aliased icons composite cleanly over the field layer.

Drawing waits for the first paint event to set hasPainted = true, calls stage.begin() before any stage.upload(), and splits rendering into two passes inside MAGNET_FRAG. Pass 0 draws #mf-backdrop, adds recessed rest sockets under each tile, pulses concentric equipotential rings around the pointer and bends luminous magnetic flux arcs toward every engaged button. Pass 1 renders each button onto a quad padded by 28 px so directional liquid elongation along (p - buttonCenter) and edge rim glow extend cleanly outside the rest rectangle without clipping.

Each tile runs a sub-stepped damped spring driven by explicit tMs timestamps. While the pointer sits within pullRadius (120 px by default), the tile leans and stretches toward the pointer; crossing past the escape radius breaks the tether with hysteresis and fires an underdamped recoil back to its resting socket. After every draw, syncGeometry() updates every button's hit box via updateElementGeometry() scaled by geometryUnit() and flips dataset.hitTick so clicks land on the pulled pixel coordinates. An IntersectionObserver and visibilitychange pause the loop off screen, ?route=2d falls back to 5-argument drawElementImage() calls, and webglcontextlost moves the backdrop and buttons into #plain-host.

Live checks

Each check builds an isolated fixture on testStage() without touching the demo above. Press Run to test this browser.

Findings