Jump to content
Search Community

Reverse Function Not Working As Expected

robs test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I have a Dropdown Navigation with sub-menu-points that are revealed on click.

For this I created a timeline with 2 tweens:

  1. A tween that changes the height and opacity of the next menu points
  2. A tween that animates the menu points from left to right.


The forward animation works fine but the reverse function only reverses the second tween — however without any animation. The first tween isn't reversed at all.


Any idea on what I did wrong?


Thanks so much.

See the Pen VqGROw by rob83 (@rob83) on CodePen

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums. 


Thanks for the demo.


The biggest problem is that you create a new timeline on every click. 

Please see the console logs in this demo: 

See the Pen gZdVbL?editors=0011 by GreenSock (@GreenSock) on CodePen


If the menu is already open, there is no need for a new timeline. 

You really want to reverse the timeline that was created on the previous click, not one that was just made.


There are a few ways to go about this, but your end result needs to be that each menu has a reference to its own animation that it is in charge of playing or reversing. 


Probably the best approach to this setup is what @OSUblake does in this thread 



This version from @pointC may be a little easier to understand (you would have to change the interaction to be click-based of course)



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



and a similar approach


See the Pen WxgdRz by GreenSock (@GreenSock) on CodePen







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