Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Ginger Soul

Is there a way to leverage ScrollTrigger's matchMedia functionality without wrapping timelines in the function?

Recommended Posts

Hey folks, 

 

Long time since my last post, but I've been working with GSAP again and I'm loving the Scrolltrigger. 

 

I'm curious if there is any way to get matchMedia functionality inside a timeline, or if there are other ways to reference it besides wrapping all your timelines with the matchMedia function. 

 

Can you 'ask' the matchmedia function whether it matches, on a timeline-by-timeline basis? 

 

I'm imagining something like this (pardon me if this looks ridiculous, I'm working on populating a timelines object from data-attributes using a loop, and wrapping all the 'eaches' in the 'kosher' matchMedia way is proving difficult).  

 

 

    tl = gsap.timeline({
          scrollTrigger: {
            matchMedia: '(min-width:800px)',
            trigger: '.element',
            start: 'top bottom',
            end: 'bottom top',
            scrub: true
          }
     }); // end timeline

Thanks, DB

Link to comment
Share on other sites

Gonna guess this is a no. 

I'll try to re-jigger the architecture on my end to place the timelines inside the proper .matchMedia functions. 

 

DB

Link to comment
Share on other sites

Hey Ginger. No, you can't pass in a media query to a ScrollTrigger like that. If you need something like that you should wrap it in a ScrollTrigger.matchMedia() function.

 

However, depending on what you're trying to do you might be able to do it with a regular matchMedia check. Perhaps if you shared a minimal demo of your situation we can better guide you as to what's best.

Link to comment
Share on other sites

Thanks, Zach. I'll put something together for you. Sorry for leaving that out, this was so...speculative that it seemed like I should ask first. 

 

DB

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×