Blog

GSAP ScrollTrigger examples: 10 scroll animations you can rebuild with AI

Ten GSAP ScrollTrigger patterns with working React code: batched reveals, progress bars, pinned steps, horizontal galleries, parallax, scrubbed video and more, plus how to prompt an AI tool for each.

A tall web page of glass sections sliding along a scroll track, one section pinned and glowing, with a scrollbar and a mouse beside it
ScrollTrigger pins, scrubs and reveals sections as the reader scrolls.

How to read these examples

GSAP is a timeline animation library; ScrollTrigger is the plugin that links a timeline to the scroll position. Since 2025 GSAP and every plugin, including SplitText and the former members-only ones, are free for commercial use, so all ten patterns below cost nothing to ship.

Each example has the React code (using the useGSAP hook from @gsap/react, which cleans up on unmount), the situation it suits, and one line you can paste into Claude Code or Cursor to get it built. A note on honesty: the BuildMotions templates mostly build these patterns with CSS and small hooks rather than GSAP, to keep bundles light. Where a template shows the pattern, it is linked so you can see the effect live.

Setup used by every example
'use client';
import { useRef } from 'react';
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { useGSAP } from '@gsap/react';

gsap.registerPlugin(ScrollTrigger, useGSAP);

export function Section({ children }: { children: React.ReactNode }) {
  const scope = useRef<HTMLElement>(null);
  useGSAP(() => {
    // each example's code goes here; selectors are scoped to this section
  }, { scope });
  return <section ref={scope}>{children}</section>;
}

1. Batched fade-and-lift reveals

The most useful scroll animation is also the quietest: cards fade in and rise a little as they enter. ScrollTrigger.batch groups elements that enter together, so a row of cards staggers as a set instead of firing one trigger per card.

Use it for feature grids, logo rows and blog lists. Prompt: "Reveal .card elements with ScrollTrigger.batch: opacity 0→1, y 24→0, 0.6 s, stagger 0.08, start top 85%, once."

gsap.set('.card', { opacity: 0, y: 24 });
ScrollTrigger.batch('.card', {
  start: 'top 85%',
  once: true,
  onEnter: (batch) => gsap.to(batch, { opacity: 1, y: 0, duration: 0.6, ease: 'power2.out', stagger: 0.08 }),
});

2. A reading progress bar

A thin bar at the top that fills as the reader scrolls tells them how long the page is. Scale the bar on the x axis with scrub: true so it tracks the scroll exactly, and set ease to none, because any easing makes the bar lag behind the scrollbar.

Prompt: "Add a 3 px progress bar fixed to the top that scales from 0 to 1 on x across the whole page, scrubbed, ease none, transform-origin left."

gsap.fromTo('.progress', { scaleX: 0 }, {
  scaleX: 1,
  ease: 'none',
  scrollTrigger: { trigger: document.documentElement, start: 'top top', end: 'bottom bottom', scrub: true },
});

3. Pinned steps ("how it works")

Pin a section while three or four steps play through, then release it. This is the pattern most product pages use to explain a workflow, and the one that most often goes wrong: keep the pinned distance short (about 200% of the viewport for three steps) or readers feel stuck.

The ORREN Energy template uses the same idea for its chapter titles over the film, with numbered markers that show where you are.

const tl = gsap.timeline({
  scrollTrigger: { trigger: '.steps', start: 'top top', end: '+=200%', pin: true, scrub: 0.6 },
});
tl.from('.step-1', { opacity: 0, y: 30 })
  .to('.step-1', { opacity: 0, y: -30 }, '+=0.4')
  .from('.step-2', { opacity: 0, y: 30 })
  .to('.step-2', { opacity: 0, y: -30 }, '+=0.4')
  .from('.step-3', { opacity: 0, y: 30 });
ORREN Energy template: three headline lines reveal over a mountain film, with chapter markers 01 02 03
ORREN Energy: staged headline lines over a scroll-driven film, with chapter markers.

4. A horizontal scrolling gallery

Vertical scrolling moves a horizontal track: good for case studies or product shots that read as a sequence. The distance must be computed from the track width, and invalidateOnRefresh recalculates it when the window resizes.

Prompt: "Pin .gallery and translate .track on x by -(track width - viewport width), scrub 1, end after the track width, recalculate on refresh." On phones, swap it for a native horizontal scroll with snap points; pinning long tracks on small screens is tiring.

const track = document.querySelector<HTMLElement>('.track')!;
gsap.to(track, {
  x: () => -(track.scrollWidth - window.innerWidth),
  ease: 'none',
  scrollTrigger: { trigger: '.gallery', pin: true, scrub: 1, end: () => '+=' + track.scrollWidth, invalidateOnRefresh: true },
});

5. Parallax layers with data attributes

Give each layer a data-speed and let one tween move them all at different rates. Keep the differences small (a few percent); strong parallax causes motion sickness and is the first thing to turn off with reduced motion.

gsap.to('[data-speed]', {
  yPercent: (_, el) => -Number((el as HTMLElement).dataset.speed) * 12,
  ease: 'none',
  scrollTrigger: { trigger: '.hero', start: 'top top', end: 'bottom top', scrub: true },
});

6. Word-by-word headline reveal

Split the headline into words (SplitText is now free; for one heading, splitting by hand is fine), then reveal them in sequence as the heading enters. Keep the original text in the DOM for screen readers, with the split spans marked aria-hidden, so the heading is still read as one sentence.

Prompt: "Split the h2 into words, reveal them with a 0.05 s stagger from y 100% inside overflow-hidden wrappers when the heading is 80% down the viewport."

7. Numbers that count up once

Stats count from zero when they first appear. Tween a plain object and write the rounded value into the element; once: true stops it replaying when the reader scrolls back. Put the final number in the HTML first so it is correct without JavaScript and for search engines.

document.querySelectorAll<HTMLElement>('[data-count]').forEach((el) => {
  const target = Number(el.dataset.count);
  const value = { n: 0 };
  gsap.to(value, {
    n: target, duration: 1.2, ease: 'power1.out',
    onUpdate: () => { el.textContent = Math.round(value.n).toLocaleString(); },
    scrollTrigger: { trigger: el, start: 'top 85%', once: true },
  });
});

8. Scroll-scrubbed video

Pin the section and set the video’s currentTime from the scroll progress, so scrolling plays the film forwards and backwards. Two details decide whether it feels smooth: encode the clip with frequent keyframes (scrubbing jumps to the nearest one), and show the poster until the video can play.

Dozens of BuildMotions templates are built around custom-made films; the Aurel Bay travel site and the scroll video templates show the effect, built with a lightweight hook instead of GSAP.

const video = document.querySelector<HTMLVideoElement>('.film')!;
ScrollTrigger.create({
  trigger: '.film-section', start: 'top top', end: '+=300%', pin: true, scrub: true,
  onUpdate: (self) => { if (video.duration) video.currentTime = self.progress * video.duration; },
});
Aurel Bay travel template mid-scroll, with a film scene and chapter text
Aurel Bay: chapters of a film that move with the scroll.

9. Sticky image, changing text

An image stays pinned on one side while text blocks scroll past on the other, and the image crossfades to match the active block. It explains a product in stages without asking the reader to look in two places. On phones, drop the pin and place each image above its text block.

10. A header that hides on the way down

Hide the header while the reader scrolls down and bring it back as soon as they scroll up. ScrollTrigger reports the direction on every update, so this needs no scroll listener of your own.

const header = document.querySelector('header')!;
ScrollTrigger.create({
  start: 0, end: 'max',
  onUpdate: (self) => header.classList.toggle('is-hidden', self.direction === 1 && self.scroll() > 120),
});

Respect reduced motion in one place

gsap.matchMedia lets you register animations only when the reader has not asked for reduced motion, and it reverts them automatically if the setting changes. Wrap every scroll effect in it and you never need a separate fallback branch.

The same rule holds in the Northline template, where the numbered reveals simply appear in place when motion is reduced.

const mm = gsap.matchMedia();
mm.add('(prefers-reduced-motion: no-preference)', () => {
  // register examples 1–10 here
});
mm.add('(prefers-reduced-motion: reduce)', () => {
  gsap.set('.card, .step-1, .step-2, .step-3', { opacity: 1, y: 0 });
});
Northline template section with a large headline and three numbered columns
Northline: numbered columns that reveal in order, and simply appear with reduced motion.

Mistakes that make ScrollTrigger pages feel broken

Most complaints about scroll animation come from a short list of avoidable problems. Check for these before you ship:

  • Pins that are too long. If a reader scrolls for three screens and the page barely changes, they assume it is broken. Start at 150–200% and shorten from there.
  • Layout that changes after the triggers are measured. Images without width and height, or fonts that load late, shift every start and end point. Set image dimensions and call ScrollTrigger.refresh() after fonts load.
  • Animating layout properties. Tweening top, height or margin forces layout on every frame; transform and opacity stay smooth.
  • Markers left in production. markers: true is invaluable while tuning and embarrassing in a client demo.
  • Hiding content until JavaScript runs. If the initial state is opacity 0 in CSS and the script fails, the section stays invisible. Set the hidden state from JavaScript instead.

Prompting an AI tool for scroll animation

AI coding tools write good GSAP when the prompt gives them what ScrollTrigger needs: the trigger element, the start and end positions, whether it scrubs or plays once, whether it pins, the easing, and the reduced-motion behaviour. Leave any of these out and the tool guesses, usually with a pinned section that is far too long.

If you would rather start from finished, tested scroll pages, the scroll storytelling templates include prompts that specify every one of these values, plus the source code. Plans start at $9 a month.

Questions

Is GSAP free to use commercially?
Yes. Since 2025 GSAP and all of its plugins, including ScrollTrigger and SplitText, are free for commercial projects.
How do I use ScrollTrigger in React or Next.js?
Register the plugin once, then create animations inside the useGSAP hook from @gsap/react with a scope ref. It reverts the animations when the component unmounts, which avoids duplicate triggers in development.
Do I need GSAP for scroll animations?
Not always. Simple reveals work with IntersectionObserver and CSS, and modern browsers support CSS scroll-driven animations. GSAP earns its place for pinned, scrubbed sequences and complex timelines.
Do BuildMotions templates use GSAP?
Most use CSS and small React hooks to keep bundles light. The prompts describe the motion precisely, so you can ask your AI tool to build it with GSAP instead. See the scroll storytelling templates.

Ready to build? Browse the template library, copy a prompt, or compare the plans.