Jump to content
Search Community

Different Scrolltrigger triggers with matchMedia?

dfreerider test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

Hi,

 

I have an animation where I want a different scrollTrigger trigger to drive the animation based on if it is on mobile or desktop. I've tried to use matchMedia to do this but it's not working.

 

I was thinking I could do something like the following, and check for mobile when setting the trigger:

 

let mm = gsap.matchMedia();
mm.add ({
  isMobile: "(max-width:800px)",
  isDesktop: "(min-width:801px)",

}, (context) => {
   let {isMobile, isDesktop } = context.conditions;
  
   let tl = gsap.timeline({
        scrollTrigger :{
            trigger:isMobile ? mobile_class_name : class_name,
            
  

 

First of all, I'm wondering if it is possible to use matchMedias to achieve this? It's always possible I have another bug in my code that prevents this from working :)

 

If it is not possible to use matchMedia to do this, I was wondering how I can best achieve this in another way?

 

Thank you!

 

Best

 

Espen

 

Link to comment
Share on other sites

  • dfreerider changed the title to Different Scrolltrigger triggers with matchMedia?

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.
×
×
  • Create New...