Jump to content
GreenSock

Romanus

direction in ScrollTrigger

Go to solution Solved by GreenSock,

Recommended Posts

Hey! I forgot how to find scroll direction in ScrollTrigger. onUpdate fires a lot of times. And I need only when the direction changes. I looked in the documentation and couldn't find

Link to comment
Share on other sites

It seems to be possible to do this by storing the value in a variable and comparing it. Works great) Do you think several onUpdates will heavily load the user's computer? Does it make sense to do one check and pass it to the right components?

Link to comment
Share on other sites

  • Solution
3 hours ago, Romanus said:

It seems to be possible to do this by storing the value in a variable and comparing it. Works great) Do you think several onUpdates will heavily load the user's computer? Does it make sense to do one check and pass it to the right components?

I wouldn't worry about it at all. It's cheap. 

ScrollTrigger.create({
  ...
  onUpdate: self => {
    if (self.direction !== self.prevDirection) {
      console.log("toggled!");
      self.prevDirection = self.direction;
    }
  }
});

 

  • Like 2
  • Thanks 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.
×