Jump to content
Search Community

How to set ScrollTrigger onLeave action to trigger function only once

Ozzy test
Moderator Tag

Recommended Posts

Hi, I am working on the NuxtJS GSAP application and using ScrollTrigger to animate elements based on the scrolled position.
First of all, I am amazing how great this plugin works, but I have a question regading the actions.
So, as mentioned in the documentation, using onLeave fires at the end of the animation, which is exactly what I need, since when the scrollTrigger animation is done, I want to call another function. The issue I have is that the onLeave fires every time the scrollTrigger is done (In case user scrolls up and then scrolls down) and what I need is to fire this additional function only once, the first time scrollTrigger animation is done. 
Is there a way of doing it once?

          onLeave: () => this.functionName(),
Link to comment
Share on other sites

Hey @Ozzy,

 

Does ONCE do the job in your setup?

 

once Boolean - If true, the ScrollTrigger will kill() itself as soon as the end position is reached once. This causes it to stop listening for scroll events and it becomes eligible for garbage collection. This will only call onEnter a maximum of one time as well. It does not kill the associated animation. It's perfect for times when you only want an animation to play once when scrolling forward and never get reset or replayed. It also sets the toggleActions to "play none none none".

 

Happy scrolling ...

Mikel

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