I can't tell you how many hundred's of questions I've seen in the GreenSock forums about controlling GSAP animations on scroll. I'm so happy there is finally a genuine GreenSock tool to power the future of scroll-driven animations.
Before I get into the specifics, it's worth a moment of time to honor those that got us here.
A short history of Scroll-driven Animations
John Polacek paved the way in 2013 with Superscrollorama, a jQuery plugin that used GSAP under the hood. Many amazing sites were created with this highly-acclaimed, ground-breaking, and trend-setting tool.
In 2014 Jan Paepke took the reins and did a complete re-write and SuperScrollarama became ScrollMagic. ScrollMagic was hugely successful as it offered a slew of new features. Excellent demo files made the tool easy for beginners to understand. Awards sites exploded with many clever effects made with the ScrollMagic and GSAP combo.
However, as with many solo-led open source projects, it's popularity created a hefty support burden that couldn't be managed.
As issues went unanswered in the ScrollMagic repo, more users found their way to the GreenSock forums asking for support on a product GreenSock didn't create or have any way of fixing.
ScrollTrigger is born
On June 1st, 2020, GreenSock released ScrollTrigger to a sold out audience via a historic YouTube Premiere.
ScrollTrigger was built with a totally fresh perspective on how GreenSock animations should be controlled via scroll. Not only does the API offer more features than it's predecessors, but it has a strong focus on performance which really shines in this "mobile-first" world. And as you can expect with any GreenSock product support is phenomenal.
For a full list of features, you'll need to check out GreenSock's ScrollTrigger API Docs, but my job here is to get you up and running quickly... so let's go!
Watch the Video
As always, I load my videos up with info so that I don't have to write a ton of stuff, but here are some key points.
Get ScrollTrigger and GSAP
ScrollTrigger is hosted on a CDN along with GSAP. Just use the script tags below to load it into your page.
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/ScrollTrigger.min.js"></script>
You can get recent CDN Urls from the GSAP Overview in the docs.
For use with npm or more advanced build tools check out the GSAP installation videos.
Super Basic Demo with a Single Tween
The animation is super slow so that you can see how the animation reacts to entering and leaving the scroller-start and scroller-end positions.
Control a Timeline with ScrollTrigger
GreenSock's Toggle Action Demo
In the video I explained how toggleActions work and how important they are. For each toggle event (onEnter, onLeave, onEnterBack, onLeaveBack) you can assign an action (play, pause, restart, reset, resume, complete, reverse, none). You'll assign a toggleAction via a 4-part string like "restart pause resume reverse".
The best way to understand how they work is to play with the values in the demos above and study the demo below.
I'm hoping these resources help get you up and running quickly. For more inspiration check GreenSock's massive collection of ScrollTrigger Demos.
I've only scratched the surface of what ScrollTrigger can do. I'll definitely be creating more training on this awesome tool.
If you need help learning GSAP and want to take your skills to the next level check out my courses at CreativeCodingClub.com.