Jump to content


Reverse a timeline not using .reverse

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

Hi all!

As you can see in my codepen, clicking the white boxes opens up the box to fill the screen relative to the position you have dragged it to. Once you then click the white button again it closes the box and puts it back where you dragged it to initially. This all happens via the lovely .reverse which is fantastic. Obviously the .reverse cycles through the timeline backwards so it is able to figure out where the box was initially. What I was hoping to figure out (and have been curious about this for ages now) - how would I go about  storing the initial coordinates that the boxes were (or any initial timeline variable) and then animating back to them should I wish. The main point of this would be that in some instances I don't want to do an exact reverse of the timeline that has initially fired, but to still reference some of the data from the timeline.


Hope this makes sense to the wizards on here.


Thank you.


See the Pen mAArVO by olichalmers (@olichalmers) on CodePen

Link to comment
Share on other sites

That's not really data that we expose via the API for several reasons:

  1. The values aren't always simple and clean, and we must store them in ways that are optimized for performance. For example, boxShadow is a string with a bunch of individual values in it, as is transform and sometimes borderRadius or border, etc. We bust them up into their components and often have to perform unit conversions as well, and get down to the bare numbers and normalize all the units. That's what we ultimately store, and it can be a little different for each plugin (again, optimized for performance). 
  2. Some values just don't lend themselves to this sort of thing, like what would you expect to get back if you checked throwProps or physics2D or drawSVG that had complex values? 
  3. To limit API complexity. 

But if your goal is to get back to the original values, you should be able to pretty easily rewind the tween/timeline with seek(0), then snag whatever you want (like element.style.property) and then jump back to wherever the tween/timeline was. 


Does that help? 

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.