Jump to content
Search Community

GSAP ScrollTrigger only run on desktop

chrisdb test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

  • Solution

Here you go!

See the Pen YzJQGbz?editors=0010 by GreenSock (@GreenSock) on CodePen



 

// create
let mm = gsap.matchMedia();

// add a media query. When it matches, the associated function will run
mm.add("(min-width: 800px)", () => {

  // put all your animations in here
  gsap.to(...);
  gsap.from(...);
  ScrollTrigger.create({...}); 

  return () => { // optional
    // custom cleanup code here (runs when it STOPS matching)
  };
});

 

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Cassie said:

Here you go!
 

 


 

 

 

// create
let mm = gsap.matchMedia();

// add a media query. When it matches, the associated function will run
mm.add("(min-width: 800px)", () => {

  // put all your animations in here
  gsap.to(...);
  gsap.from(...);
  ScrollTrigger.create({...}); 

  return () => { // optional
    // custom cleanup code here (runs when it STOPS matching)
  };
});

 

Thankyou Cassie thats worked perfectly. Appreciate the speedy response. Another quick question...

 

When the white section scrolltrigger hasnt kicked in I want to have the text color white so its visible on the dark background then change to black once the white background has come into view. How would I include this?

Link to comment
Share on other sites

1 minute ago, Cassie said:

Not sure I understand entirely, are you saying without scrollTrigger it's the wrong colour?

You can use media queries in CSS to affect styling too if so

 

@media only screen and (min-width: 800px) {
  .el {
    color: something
  }
}

 

 

I want the text once the scrolltrigger changes the background to white to change the h2 & p text from white to black. At the moment the text stays dark and you cant see the text before the scrolltrigger changes the background to white. Sorry struggling to explain this, hope this helps.

 

  • Like 1
Link to comment
Share on other sites

If you're asking how to make that text white before the animation kicks in, then you'll have to change that in your styles.

this is the bit that's making the text dark in that section

 

.color-light p, .color-light h2 {
    color: var(--dark);
}

 

Link to comment
Share on other sites

16 minutes ago, Cassie said:

If you're asking how to make that text white before the animation kicks in, then you'll have to change that in your styles.

this is the bit that's making the text dark in that section

 

.color-light p, .color-light h2 {
    color: var(--dark);
}

 

I need the text to change after the animation kicks in

  • Like 1
Link to comment
Share on other sites

Ok, so that's because your CSS here is higher in specificity than the tween is

 

.color-light p, .color-light h2 {
    color: var(--dark);
}
gsap.to("body", {
 color: "red",
}),


I don't know where that styling is coming from, I see you have bootstrap loaded too. So you have two choces, either get rid of the styling so there's no conflicts on adjust your tween/add an animation to target those elements specifically
 

gsap.to("body, .color-light p, .color-light h2", {
 color: ...,
}),

 

  • Like 1
Link to comment
Share on other sites

5 minutes ago, Cassie said:

Ok, so that's because your CSS here is higher in specificity than the tween is

 

.color-light p, .color-light h2 {
    color: var(--dark);
}
gsap.to("body", {
 color: "red",
}),


I don't know where that styling is coming from, I see you have bootstrap loaded too. So you have two choces, either get rid of the styling so there's no conflicts on adjust your tween/add an animation to target those elements specifically
 

gsap.to("body, .color-light p, .color-light h2", {
 color: ...,
}),

 

Found the issue Cassie, thanks again for the help. Have a lovely day!

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