October 16, 2025

GSAP (GreenSock Animation Platform) is a powerful JavaScript library for creating high-performance animations, and its ScrollTrigger plugin takes it to the next level by enabling scroll-based animations with precise control. ScrollTrigger allows developers to create engaging, interactive experiences that respond to the user's scroll position. This blog dives into everything you need to know about ScrollTrigger, including its core features, configuration options, and practical examples.
ScrollTrigger is a free plugin for GSAP that lets you trigger animations based on the scroll position of an element or the viewport. It’s highly customizable, supporting features like pinning, scrubbing, snapping, and toggle actions, making it ideal for creating immersive web experiences. Whether you’re animating elements as they enter the viewport or building complex scroll-driven interactions, ScrollTrigger provides the tools to make it happen seamlessly.
To use ScrollTrigger, you need to include the GSAP core library and the ScrollTrigger plugin in your project:
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/ScrollTrigger.min.js"></script>
Then, register the plugin:
gsap.registerPlugin(ScrollTrigger);
ScrollTrigger works by associating animations with the scroll position of a trigger element relative to a scroller (usually the viewport). Here’s a breakdown of its key configuration options, based on the provided settings:
The
triggertrigger: ".selector"trigger: document.querySelector(".my-element")The
startend"[trigger position] [scroller position]"topcenterbottom20px80%topcenterbottomstart: "top center"end: "+=500"The
scrubtrue1scrub: trueThe
pintruepin: ".selector"pinSpacing: falsepinReparent: truedocumentElementThe
markersstartendmarkers: trueThe
toggleActionsplaypauseresumeresetrestartcompletereversenone"onEnter onLeave onEnterBack onLeaveBack"toggleActions: "play pause resume reset"The
toggleClasstoggleClass: "active"activeThe
fastScrollEndtruefastScrollEnd: trueThe
containerAnimationcontainerAnimation: tweentweenThe
snapsnapTo: 1 / 10"labels"durationdirectionaleaseonCompleteonStartonInterruptsnap: {
snapTo: 1 / 10,
duration: 0.5,
directional: true,
ease: "power3"
}
ScrollTrigger provides a range of callbacks to hook into various events:
onEnteronLeaveonEnterBackonLeaveBackonUpdateonToggleonRefreshonRefreshInitonScrubCompleteonEnter: () => console.log("Entered viewport")id: "my-id"anticipatePin: 1pinType: "transform""fixed"pinnedContainer: ".selector"preventOverlaps: trueonce: trueendTrigger: ".selector"endhorizontal: trueinvalidateOnRefresh: truerefreshPriority: 1Here’s a complete example of a ScrollTrigger animation that fades in a box and pins it while scrolling:
gsap.to(".box", {
opacity: 1,
y: 100,
duration: 1,
scrollTrigger: {
trigger: ".box",
start: "top 80%",
end: "+=300",
scrub: true,
pin: true,
markers: true,
toggleActions: "play pause resume reset",
onEnter: () => console.log("Box entered viewport"),
onUpdate: (self) => console.log("Progress:", self.progress)
}
});
.box.boxscrub: truepin: truemarkers: truewill-change: transforminvalidateOnRefresh: truemarkers: truescrubhorizontal: truesnapGSAP ScrollTrigger is a game-changer for scroll-based animations, offering unmatched flexibility and control. Its extensive configuration options allow you to create everything from simple fade-ins to complex, scroll-driven experiences. By mastering its features like pinning, scrubbing, and snapping, you can elevate your web projects to new heights. Experiment with the provided settings, and check out the GSAP documentation🔗 for more inspiration!