Jump to content
Search Community

onComplete won't work after tl.reverse()

alx test
Moderator Tag

Recommended Posts

Greetings! To replicate my problem, I created this simple codepen. I can't figure it out😵. All I want is: click on the 'link' -> menu animation reverses -> 'container' turns red. This is where the onComplete comes in; the sequence is important for just one reason, the 'container' turning red is actually going to be the destination of the link or simply speaking, the window.location. Basically, the menu will close like it opened and then the browser can refresh...but because I can't get the onComplete to work, the brower refreshes while truncating the animation.

See the Pen abXomzz by alxhrrs (@alxhrrs) on CodePen

Link to comment
Share on other sites

Hi @alx

 

The .reversed() function doesn't have call backs https://gsap.com/docs/v3/GSAP/Timeline/reversed()/, but the .tweenTo() does and because we can be sure that the link is visible when the timeline has played there will be no need to check where the animation is an play it in any direction, we can play the playhead to zero and then watch for an onComplete to turn the background red. https://gsap.com/docs/v3/GSAP/Timeline/tweenTo()

 

Hope it helps and happy tweening! 

 

See the Pen wvNwrWL?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen

Link to comment
Share on other sites

Yeah mvaneijgen.....that helped! That was it! Next time, instead of spending 2 days trying to fix it myself, I'll just post on the forum😆. I really appreciate the fix and explanation. Here's how I applied it (the last section of code) to the actual project...

$("#menu-main-menu a").click(function(event){	
	event.preventDefault();
	let destination = $(this).attr("href");	
	tl.tweenTo(0, {
		onComplete: () => {
		  window.location = destination;
		}
  	})
});	

So now the browser successfully waits for the reversed menu animation to finish, and then refreshes the window with the new page. Thanks again!!!

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