Smooth Scroll, Sub-Pixel Precision, and Zero-Idle WebGL in Astro

Engineering notes on building tactile editorial motion—Lenis smooth scroll, pinned horizontal galleries, and canvas pixel reveals—without hurting performance.


Creative web interfaces often pay a hidden tax: runaway requestAnimationFrame loops, jittery scroll-linked transforms, and megabytes of JavaScript shipped for static content.

You do not need a heavy SPA runtime to build responsive, tactile motion. With Astro’s static HTML paired with small, focused TypeScript modules, you can keep the client bundle tiny while still delivering expressive interactions.

Never leave a canvas RAF loop running when idle

Whether you are rendering a WebGL fragment shader trail or a 2D pixel-block reveal, the animation loop should only run while pixels are actively changing:

  • Start requestAnimationFrame on pointer input or state change.
  • Track per-cell expiration timestamps.
  • Stop scheduling frames the moment all active cells expire (rafId = null).

On a portfolio page, that means 0% GPU/CPU usage while someone is simply reading.

Avoid integer quantization jitter during smooth scroll

When driving a pinned horizontal gallery from vertical smooth scroll (such as Lenis), reading getBoundingClientRect().top on every frame can introduce subtle vibration right as the scroll decelerates to a stop.

Because browser layout rects often quantize to integer pixels, frame-to-frame deltas alternate between 0 and 1. Reading Lenis’s floating-point lenis.scroll directly against a cached sectionTop keeps horizontal translation and scale transitions completely monotonic and jitter-free.

Respect reduced motion by default

Every motion module should check prefers-reduced-motion: reduce before attaching listeners or splitting DOM nodes. When reduced motion is requested, text reveals render immediately in their final state and pinned galleries fall back cleanly to native horizontal scroll-snap.