Jump to content
Search Community

Two instances of scrollTrigger

csp test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Is it possible to have 2 instances of scrollTrigger? I currently have one instance on one component and then another on the component just beneath it and I'm getting some strange behavior. Side question, is it possible to use variables like vh for end values? Thanks!

Link to comment
Share on other sites

  • Solution

Hi,

 

You can have as many ScrollTrigger instances as you want/need, just be super careful about creating them in the order they appear on the screen. Unfortunately without a minimal demo there is not a lot we can do to help you. You can fork this codepen in order to create a small demo that clearly illustrates the issue you're having, no need for your entire project, just a few colored divs.

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

2 hours ago, csp said:

Side question, is it possible to use variables like vh for end values?

I don't see why not, but it might be safer to use percentages since ScrollTrigger makes all the calculations based on the viewport's height and is 100% reliable. Personally I always use percentages without any issues:

ScrollTrigger.create({
  trigger: ".my-element",
  start: "top top",
  end: "+=250%",
});
// This will end when the scroll position has moved 2.5 times
// the height of the viewport after the start point, since is
// a relative value because of +=

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Thanks Rodirigo, the percentage info helped solve my problem for why the second instance wasn't working properly. Thank you so much!

  • 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...