Jump to content
Search Community

Help with timeline reverse

NickNo test
Moderator Tag

Recommended Posts

Hi, I have some legend keys that animate in with a switch toggle - when I toggle them off, I want the legend to animate back out (reverse()) - but the way I have setup it up, it isn't working - can someone shed some light on why?  Also, I'm creating the timeline on each toggle of the checkbox, which I realise isn't very efficient. Is there a better way to set it up, keeping in mind the #legendid will be dynamic (on some  pages there will be 2 legends, 3 on others and they will all have different #ids)?

See the Pen dymvBer by nickjacobsnz (@nickjacobsnz) on CodePen

Link to comment
Share on other sites

You have it set up so that every time you click, the timeline is recreated. Since you are using .to, all the animation values are relative from the time of creation.

The first time you click the toggle, it opens the legend because it's going from an invisible state to a visible one.

The next time you click the toggle, it recreates the timeline. It looks at the properties on the legend, says "we need to go TO that" but it is already there. So when you reverse it, you are just going to the current values.

You have to create your timelines outside of the event that reverses it or use .fromTo tweens. The former is probably better than the latter.

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