FINDING YOUR DIRECTION

0%
← Scrollhaus Journal

AI Website Guides · Published · Updated · 5 min read

GSAP ScrollTrigger Examples: 8 Patterns With Code (2026)

GSAP ScrollTrigger links animation to scroll position. Here are eight copy-ready patterns, from pinned sections to scrubbed canvas film, with the code and the gotchas that matter in production.

Published by Amanjot Singh, founder of Scrollhaus. AI-assisted editorial work; product context, sources and corrections are documented in our editorial methodology.

A pinned scroll-driven section from an animated website
Scrollhaus Journal · AI Website Guides

Disclosure: ScrollHaus publishes this guide. Technique descriptions come from public documentation of the libraries and browser APIs named, and the live examples are ScrollHaus websites you can scroll yourself.

What is GSAP ScrollTrigger?

ScrollTrigger is a GSAP plugin that starts, pauses, reverses or scrubs animations based on scroll position. Setup is always the same: register the plugin, create a tween or timeline, and give it a scrollTrigger object describing the trigger element and the start and end points.

import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger);

1. Fade and rise on enter

gsap.from('.card', {
  y: 40, opacity: 0, duration: 0.8, stagger: 0.12,
  scrollTrigger: { trigger: '.cards', start: 'top 80%' }
});

2. Pin a section while it plays

Pinning holds an element in place for a scroll distance so the story can progress.

ScrollTrigger.create({
  trigger: '.story', start: 'top top', end: '+=2000', pin: true
});

3. Scrub a timeline with the scrollbar

scrub: true ties progress directly to scroll, so scrolling back rewinds the animation. A number such as scrub: 0.6 adds a little smoothing.

gsap.timeline({
  scrollTrigger: { trigger: '.story', start: 'top top', end: '+=3000', scrub: 0.6, pin: true }
})
.to('.title', { scale: 1.4, opacity: 0 })
.from('.panel', { yPercent: 100 }, '<0.3');

4. Horizontal scroll section

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

5. Text reveal line by line

Split headlines into lines (GSAP SplitText or your own wrapper) and stagger them up from a mask. Keep the real heading text in the HTML so search engines can read it.

6. Parallax layers

gsap.utils.toArray('[data-speed]').forEach((el) => {
  gsap.to(el, { yPercent: -el.dataset.speed * 20, ease: 'none',
    scrollTrigger: { trigger: el, scrub: true } });
});

See parallax website examples for design patterns.

7. Scroll progress bar

gsap.to('.progress', { scaleX: 1, ease: 'none', transformOrigin: 'left',
  scrollTrigger: { scrub: true, start: 0, end: 'max' } });

8. Scrub a canvas image sequence

ScrollTrigger can drive a frame counter, and a canvas draws the frame for the current value. This is the same idea as our image sequence canvas tutorial.

const state = { frame: 0 };
gsap.to(state, {
  frame: TOTAL - 1, snap: 'frame', ease: 'none',
  scrollTrigger: { trigger: '.runway', start: 'top top', end: 'bottom bottom', scrub: 0.5 },
  onUpdate: () => draw(state.frame)
});

How ScrollTrigger works: start, end and the viewport

Every example above uses the same model. A ScrollTrigger watches one trigger element and compares it with the viewport during native scroll. The start and end values decide when it is active. start: "top 80%" fires when the top of the element reaches a line 80% down from the top of the viewport. end: "bottom top" fires when the bottom of the trigger reaches the top of the viewport, and endTrigger lets a different element set the end position. While you build, add markers: true to draw visual markers for each start and end.

toggleActions or scrub

With toggleActions, scroll triggers only decide when to play the animation. A tween will play for its own duration, for example 1 second, however fast the visitor scrolls. With scrub, you link the progress of the animation directly to the scrollbar: the playhead sits at a value between 0 and 1 that matches how far the page has moved between start and end. scrub: 1 lets the playhead take one second to catch up, which smooths the motion.

When one ScrollTrigger has a timeline, the duration of each tween becomes a proportion of the scroll distance. In a single timeline where the first tween lasts two seconds and the second lasts one, the first uses two thirds of the scroll to complete. That is how complex animations stay in sync with minimal code.

Pinning, horizontal movement and callbacks

A pinned section stays fixed until the end position, then gets unpinned and vertical scroll continues. For horizontal movement, pin a wrapper and animate its panels horizontally with xPercent while the page scrolls down. Callback functions such as onEnter and onUpdate expose the overall progress, and snap moves to the closest progress value when scrolling stops. To animate multiple elements with one pattern, use ScrollTrigger.batch() instead of writing a trigger for each DOM node.

Responsive setups and smooth scrolling

ScrollTrigger will recalculate its positions after a debounced resize. Call ScrollTrigger.refresh() yourself when late images or fonts change the layout. Wrap breakpoint-specific setups in gsap.matchMedia() so media queries create one animation for desktop and a simpler one for phones. ScrollSmoother is the GSAP smooth-scrolling plugin built on top of ScrollTrigger, and the same progress value can drive a Three.js scene or plain CSS variables. The GSAP demo hub and CodePen collections are the quickest place to find a minimal demo for any of these scroll-based animations.

ScrollTrigger tips for production

Frequently confused: GSAP vs Framer Motion

GSAP gives frame-accurate scroll control and timelines in any framework. Framer Motion is declarative and React-native. Our GSAP vs Framer Motion comparison explains when each wins. Browse live scroll-driven builds in the ScrollHaus library.

Frequently asked questions

What is GSAP ScrollTrigger used for?

It links animation to scroll position so you can trigger, pin, reverse or scrub animations as the user scrolls.

What does scrub do in ScrollTrigger?

Scrub ties animation progress directly to scroll position. Scrolling back rewinds it, and a number value adds smoothing.

How do I pin a section with ScrollTrigger?

Set pin: true on a ScrollTrigger with a start and end distance such as '+=2000'. The element stays fixed while the scroll distance plays.

Why are my ScrollTrigger positions wrong?

Content changed size after setup. Call ScrollTrigger.refresh() after images and fonts load, and use invalidateOnRefresh for computed values.

Is GSAP ScrollTrigger free?

GSAP and ScrollTrigger are available free of charge for most uses. Check the current GSAP licensing page for your specific case.

Can ScrollTrigger drive a canvas animation?

Yes. Animate a frame counter with scrub and draw the matching image to a canvas in onUpdate.

Browse Scrollhaus website designs and build resources →

Need help with a template, account, or project? Email admin@scrollhaus.ai.