Jump to content
Search Community

Reversing timeline problems

jjvera 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

Hello!
I-m trying to use the same timeline on different html elements (they work as modals). 

I made three functions. One with the Animation Timeline, one with with the .restart() to trigger the animation and the last one with a .reverse().

 

But i doesn-t work properly, i think its a problem with the .set values on the elements when the animation performs at the first time, but i dont know why the reverse doesnt reverse properly. 

 

 

See the Pen NBJPLO?editors=1010 by JulianVera (@JulianVera) on CodePen

Link to comment
Share on other sites

6 hours ago, jjvera said:

But i doesn-t work properly, i think its a problem with the .set values on the elements when the animation performs at the first time, but i dont know why the reverse doesnt reverse properly. 

 

You're creating a timeline and then immediately calling reverse on it. That won't do anything because the start of an animation is also the end of animation when reversed. You would need to do something like setting the progress of the animation to 1, and then call reverse.

 

However, it would be better if you just kept a reference to the timeline, and then reversed it.

 

var tl;

//OPEN MODAL
$(".modal-trigger").click(function() {
  modalTarget = '#' + $(this).attr("data-target");
  tl = tlOpenModal(modalTarget);
});

//CLOSE MODAL
$( ".modal-close" ).click(function() {
  tl.reverse();
});

 

 

 

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