Ozzy Posted April 13, 2021 Share Posted April 13, 2021 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 More sharing options...
mikel Posted April 13, 2021 Share Posted April 13, 2021 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 2 Link to comment Share on other sites More sharing options...
Ozzy Posted April 13, 2021 Author Share Posted April 13, 2021 @mikel Great solution! Not sure how it slipped my eye Thank you very much for the quick response, have a nice day! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now