Jump to content
Search Community

How to get a non-looping value from ScrollTrigger onUpdate when you reach a section.

jjmolnar test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hey guys, i m trying to get non-looping value from scrolltrigger update function. The issue i have in the codepen is that it gets me the value every single scrolled pixel. Is there a way how to tell scrollTrigger to return the value only once? Like - ok you reached the section, i ll print your value once (f.e. "1") and then i stop updating until i reach other section i need value from.

 

Any advice is much appreciated!

See the Pen wvEpMEr by Buzzworthy (@Buzzworthy) on CodePen

Link to comment
Share on other sites

Thx for the response. I am sorry, I didn t specifiy my issue more thoroughly. What you ve provided works just great for this case, thank you.

 

But imagine we use horizontal scroll with many boxes on the far right (out of the visible window) and you want to detect when the next box is in the view. I m using onUpdate to check the position of the boxes and it can now work with onEnter as far as i know. And onUpdate, of course checks every pixel meaning i ll get that ID xxx times. I need to print the ID only once when the new box is in the view. Any idea @elegantseagulls ?

 

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