The rules I follow for motion
- Every section is readable with JavaScript off. Pinned layouts only apply under a class (for example
.js:not(.reduced)) that is set when motion can run. - A single
requestAnimationFramedriver owns scroll and frame callbacks, and modules subscribe to it instead of starting their own loops. - Per-frame code only writes transforms and CSS variables. Layout reads happen in batches on resize, never inside the frame callback.
- Motion modules are lazy-loaded when their section appears, using
data-*hooks in the markup. - Changes are judged on Lighthouse medians and touch-scroll traces from a throttled phone profile.
Illustrative example: a pinned, scrubbed section
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
const mm = gsap.matchMedia();
mm.add("(prefers-reduced-motion: no-preference)", () => {
gsap.timeline({
scrollTrigger: { trigger: ".range", start: "top top", end: "+=150%", pin: true, scrub: true },
})
.from(".range__pack", { yPercent: 40, rotate: -6 })
.to(".range__bg", { backgroundColor: "var(--flood)" }, "<");
// matchMedia reverts everything automatically when the query stops matching
});
A bug from the Eastern rebuild
On the Eastern rebuild, one visual bug came from GSAP overwriting a positioning transform on an element it was also animating. The fix was to put positioning and animation on separate wrapper elements, which I now do by default for anything GSAP animates.