December 3, 2026
You can build a scroll animation in plain JavaScript with no library. Measure where the element sits in the window, turn that into a progress number from 0 to 1, and set a style from the number. The free Enrichr Library has 46 scroll-driven examples built this way, each with a live demo, the code to copy and a pen on CodePen.
What is the basic pattern?
const el = document.querySelector(".band");
function update() {
const r = el.getBoundingClientRect();
// 0 when the top of the element reaches the bottom of the window,
// 1 when its bottom leaves the top
const p = Math.min(1, Math.max(0, (innerHeight - r.top) / (innerHeight + r.height)));
el.style.setProperty("--p", p);
}
let queued = false;
addEventListener("scroll", () => {
if (queued) return;
queued = true;
requestAnimationFrame(() => { queued = false; update(); });
}, { passive: true });
update();
The script only writes one CSS variable, --p. The look lives in CSS, for example
transform: scaleX(var(--p)) or opacity: var(--p). Because progress comes from position, the effect
reverses by itself when the reader scrolls back up.
Which examples should I start with?
| Example | What it does |
|---|---|
| Word read highlight | Words in a paragraph light up one by one as it scrolls through the window. |
| Split text reveal | A headline whose words rise out of a mask one after another when it scrolls into view. |
| Scrubbed stats band | A band grows to full width while its numbers count up, tied to scroll position and reversible. |
| Scroll spring heading | An oversized heading slides sideways with scroll progress through a spring, lagging and settling. |
| Scroll velocity skew | Text leans and splits into two colour fringes in proportion to how fast the page scrolls. |
| Mask shape sections | The same image revealed through a circle, a diamond and a band as each section scrolls into view. |
| Image compare on scroll | A before and after slider whose divider follows the scroll and can also be dragged or moved with the keyboard. |
| Folding layout 3D | A stack of panels hinged like a concertina that folds and unfolds in CSS 3D with scroll. |
| Scroll camera landscape | A low-poly mountain range the camera flies through as you scroll, drawn with WebGL. |
The other 37 are in the Library; choose the Scroll-driven technique filter. Of the 46, 37 use CSS for the look, 9 use SVG and a few draw on canvas or WebGL.
Do I need the scroll event for a simple reveal?
No. A fade or slide that plays once when something comes into view only needs to know when that happens.
IntersectionObserver tells you, and the browser does the watching:
const io = new IntersectionObserver((entries) => {
for (const e of entries) {
if (e.isIntersecting) { e.target.classList.add("is-in"); io.unobserve(e.target); }
}
}, { threshold: 0.3 });
document.querySelectorAll(".reveal").forEach((el) => io.observe(el));
Keep the scroll-position pattern for effects that must follow the scroll, forwards and backwards.
When is a library worth it?
When the job is coordination. A pinned section with ten animations that must stay in step, a timeline you want to rearrange often, or SVG morphing are all easier with GSAP and ScrollTrigger. GSAP is free to use now; see is GSAP free? for the terms. For one band, one headline or one counter, plain JavaScript is less to load and less to keep up to date.
What about reduced motion and speed?
- Check
matchMedia("(prefers-reduced-motion: reduce)")and show the finished state without moving anything. - Animate
transformandopacity. They do not force the page to lay itself out again. - Do the work once per frame, as in the pattern above, never straight in the scroll handler.
Each Library element page has an accessibility note saying what it does with reduced motion and for screen readers.
How do I use an example?
- Open an element and adjust its controls until it fits.
- In the Code section, press Copy for the HTML, CSS and JavaScript. Or press Copy prompt to hand it to Claude, Cursor or ChatGPT with instructions.
- Or choose Open the live pen and fork it on CodePen.
The elements are free to use in personal and client projects during the preview. Please do not resell the code as a collection.
Where to go next
- The Enrichr Library: all 175 elements.
- Recreate a GSAP scroll animation from a website.
- Find out which animation library a website uses.
FAQ
Can I make scroll animations without GSAP?
Yes. A scroll animation needs the element's position in the window, a progress number from 0 to 1 and a style set from that number. That is a few lines of plain JavaScript. A library earns its place when you have long timelines, pinning and many linked animations to keep in step.
What is a scroll-driven animation?
An animation whose progress follows the scroll position instead of a clock. Scroll down and it moves forward; scroll back up and it reverses. It is often called a scrubbed animation.
Should I use IntersectionObserver or the scroll event?
Use IntersectionObserver to know when an element enters the window, which is all a one-off reveal needs. For an effect that follows the scroll position, read the position inside requestAnimationFrame so the work happens once per frame.
Are the Enrichr Library elements free to use?
Yes, in personal and client projects during the preview. The licence note on the Library page asks that you do not resell the code as a collection.
What about people who turn animations off?
Check prefers-reduced-motion and show the finished state without moving anything. Each Library element lists what it does in that case.