Jump to content
Search Community

Pause timeline in an onComplete callback when tied to a ScrollTrigger

jackkemm test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hi there,

 

I am trying to create an animation where by the timeline only happens once when tied to a ScrollTrigger.

 

The idea is the timeline will scrub to a point in the timeline where there is an onComplete callback which should pause the timeline and not let it happen again in any direction unless the user refreshes their page.

 

I have tried killing/disabling the ScrollTrigger in this callback, but it causes a page shift to occur, plus I still need this section to pin even if the animation isn't scrubbing.

 

Any ideas on how I can stop the timeline from scrubbing once this onComplete callback runs?

 

I have attached a Codepen to hopefully give a better understanding of what i'm trying to achieve.

 

Thanks,

Jack

See the Pen QWZGGbX by jackkemm (@jackkemm) on CodePen

Link to comment
Share on other sites

  • Solution

Hi @jackkemm have you seen the once property of ScrollTrigger? From the ScrollTrigger docs

 

 

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

 

If you still want it to pin (would be weird, because nothing would be happening anymore) use two ScrollTriggers one for pining and the other for the animation which has the once: true on it. Hope it helps and happy tweening! 

 

See the Pen dygOOZe?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 1
  • 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.
×
×
  • Create New...