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.
Starting...
Show the code five drawable dock tiles, spring detachment physics, magnetic flux and liquid-stretch GLSL, geometry sync and 2D fallback
- Backdrop and five
drawabledock buttons in one canvas.#mf-backdrophosts the editable mode readout pill and status counter, while#mf-item-0through#mf-item-4stay independentdrawablebuttons. - Damped spring attraction and escape-threshold recoil. Steps each button's displacement toward the pointer inside
pullRadiusand fires an underdamped elastic snap-back once the pointer crosses the threshold, using explicittMstimestamps. - 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
uPullDirover a 28 px bleed quad. - Per-button hit alignment with
updateElementGeometry(). CalibratesgeometryUnit()once per size, updates every displaced button'scanvasTransformon each move frame and flipsdataset.hitTick. - 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
- Measured in headless Chrome 160.0.8188.0 canary (2026-11-27, 412×915 viewport at 2.625 DPR, SwiftShader WebGL): all 6 live checks pass, backing store stays at
0.79 MP(994×798,6.35 MBinitial,6.48 MBpeak),scrollWidth === innerWidth === 412,0errors,0lost contexts,0open snapshots and0wrong-argumentdrawElementImage()calls. - Pixel readbacks in
readPixels()confirm pointer proximity shifts#mf-item-2upward (dy = -37.8 px, probe luminance rising from16to46) and lights Pass 0 flux lines along the attraction path (16to142) withgl.getError() === 0. - With explicit
tMstimestamps, pulling inside120 pxsettles at-30.4 pxin39frames; crossing to138 pxdetaches the tether with a+7.8 pxdamped elastic recoil overshoot before settling back to(0, 0)in60frames, while reduced motion snaps in1step. updateElementGeometry()scaled bygeometryUnit()(1.000) moves each button's hit box cleanly: probing a pulled tile viaelementsFromPoint()hits#mf-item-2while the vacated rest edge misses it, and live CDP clicks under Hover preset register on both displacedSliceandBrushtiles.- A pairwise sibling separation pass in
evaluateTargets()keeps adjacent tiles from piling over one another toward the pointer, though it must run only when at least one tile in a pair is engaged so resting tiles keep exact(0, 0)offsets. - Both the 5-argument
drawElementImage()2D route (?route=2d,6/6checks,draws.wrong === 0) and plain-HTML fallback (CanvasDrawElementdisabled,0.00 MP) keep all five buttons and the editable pill working at412 px. Real Chrome 159 on Android andnpm run check:jank -- /magnetic-field/stay not verified.