Skip to main content

3.4 release

· 3 min read
Jack Doyle

GSAP 3.4 has arrived with some significant improvements to ScrollTrigger:

ScrollTrigger.matchMedia() ScrollTrigger.matchMedia()

You can use standard media queries to seamlessly transition between different ScrollTriggers. It's surprisingly simple to set up and let ScrollTrigger automatically handle all of the creating, undoing, and destroying for you.

Basic setup

ScrollTrigger.matchMedia({

// desktop
"(min-width: 800px)": function() {
// setup animations and ScrollTriggers for screens 800px wide or greater (desktop) here...
// These ScrollTriggers will be reverted/killed when the media query doesn't match anymore.
},

// mobile
"(max-width: 799px)": function() {
// The ScrollTriggers created inside these functions are segregated and get
// reverted/killed when the media query doesn't match anymore.
},

// all
"all": function() {
// ScrollTriggers created here aren't associated with a particular media query,
// so they persist.
}

});

loading...

There's a new ScrollTrigger.saveStyles() method that can be useful with matchMedia(). It saves the current inline styles for any element(s) so that they're reverted properly if animations added other inline styles. It's explained in the video above.

See the ScrollTrigger.matchMedia() docs for details.

ScrollTrigger.batch() ScrollTrigger.batch()

Normally, each ScrollTrigger fires its callbacks (onEnter, onLeave, etc.) immediately when they occur but what if you want to coordinate an animation (like with staggers) of ALL the elements that fired a similar callback around the same time? ScrollTrigger.batch() creates a coordinated group of ScrollTriggers (one for each target element) that batch their callbacks within a certain interval, delivering a neat Array so that you can easily do something like create a staggered animation of all the elements that enter the viewport around the same time. It's a great alternative to IntersectionObserver because it's more widely compatible and easier to work with. Plus you're not restricted to only entering or exiting the viewport - batch() can use ANY start and end values!

Demo

loading...

See the ScrollTrigger.batch() docs for details.

ScrollTrigger.scrollerProxy() ScrollTrigger.scrollerProxy()

ScrollTrigger purposefully avoids "scrolljacking" (disabling the browser's native scrolling behavior in favor of a custom, non-standard scrolling solution). However, smooth scrolling was by far the most requested feature to pair with ScrollTrigger. There are plenty of smooth-scrolling libraries out there, so we created the .scrollerProxy() method to make it simple to integrate any of them with ScrollTrigger (or create your own effects).

Here's a basic example using Locomotive Scroll but check out the .scrollerProxy() docs for examples with other libraries.

loading...


And more... And more...

GSAP 3.4 also delivers various bug fixes, so we'd highly recommend installing the latest version today. There are many ways to get GSAP - see the Installation page for all the options (download, NPM, zip, Github, etc.).

Resources Resources

Happy tweening!