Copied!
Guide

Scroll animations without a library: 46 plain JavaScript examples you can copy

You do not need an animation library for a scroll effect. The pattern is a few lines of JavaScript. Here is the pattern, and 46 finished examples with live demos and code.

← Blog
Title card: Scroll animations, no library. Preview of a scrolling grid of green tiles from the Enrichr Library.

December 3, 2026

3 min read46 live examples

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.

Try it on any site. The free animation library checker shows you which animation libraries actually run on a page (GSAP, Lenis, Framer Motion). Paste a URL, no sign-up for your first lookup.

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?

ExampleWhat it does
Word read highlightWords in a paragraph light up one by one as it scrolls through the window.
Split text revealA headline whose words rise out of a mask one after another when it scrolls into view.
Scrubbed stats bandA band grows to full width while its numbers count up, tied to scroll position and reversible.
Scroll spring headingAn oversized heading slides sideways with scroll progress through a spring, lagging and settling.
Scroll velocity skewText leans and splits into two colour fringes in proportion to how fast the page scrolls.
Mask shape sectionsThe same image revealed through a circle, a diamond and a band as each section scrolls into view.
Image compare on scrollA before and after slider whose divider follows the scroll and can also be dragged or moved with the keyboard.
Folding layout 3DA stack of panels hinged like a concertina that folds and unfolds in CSS 3D with scroll.
Scroll camera landscapeA 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?

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?

  1. Open an element and adjust its controls until it fits.
  2. 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.
  3. 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

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.