Jump to content
GreenSock

Daniel2024

Rerun animation on click after closing menu

Moderator Tag

Recommended Posts

Hello guys,

 

I am trying to animate a menu, with two different timelines (open and close). Everything works fine.

There still one little issue I need to solve: 

After closing the menu and toggle the  button to open the menu, the open-animation doesn't work / run.

 

Here is my code:

menuIcon.addEventListener('click', MenuAnimation);
var menuState = 0;
 
function MenuAnimation(){
 
if(menuState == 0 ){
menuState = 1;
 
tl.play();
 
} else if(menuState == 1){
 
tl_remove.play();
 
menuState = 0;
}
}

 

Thank you in advance.

 

Regards 

Daniel

 

See the Pen abbgBKq by Daniel2024 (@Daniel2024) on CodePen

Link to comment
Share on other sites

Hey @Daniel2024,

 

The characteristic of play() : by default playback begins from wherever the playhead currently is.

 

//begins playing from wherever the playhead currently is:
myAnimation.play();

//begins playing from start:
myAnimation.play(0);

 

See the Pen JjjQEPm by mikeK (@mikeK) on CodePen

 

Happy tweening ...

Mikel

 

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