2026-10-04 · 4 min
Scroll animation without a library, and with an off switch
One throttled scroll handler, a few CSS variables, and a rule that turns every effect off for people who ask for less motion.
The scroll effects on this site (the headline lifting away, product screenshots sliding into place, the line drawn between Bethlehem and London) add no animation library. They are CSS plus a few small hooks.
Drive CSS with one variable
A single scroll listener, throttled with requestAnimationFrame, writes a number between 0 and 1 into a CSS variable. The stylesheet does the rest with calc(), so the JavaScript never touches individual elements.
el.style.setProperty("--p", String(progress)); /* 0 → 1 */
.shot { transform: translateX(calc((1 - var(--p)) * 32%)); }Animate only transform and opacity
These two properties are composited by the GPU and do not force layout, which keeps scrolling smooth on mid-range phones.
Reveal once, with IntersectionObserver
Sections fade in the first time they enter the viewport and then stop being observed. Counters use the same trigger to count up from zero.
Always provide the off switch
Under prefers-reduced-motion the reveals show immediately, drawn lines are already complete and the hero is static. Visitors who ask their device for less motion get the same content, just still.
@media (prefers-reduced-motion: reduce) {
.reveal { opacity: 1; transform: none; transition: none; }
}