Jump to content
Search Community

Hamburger menu with DrawSvg

jp_uk81 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

Hi Guys,

I'm trying to animate this hamburger menu. The hover works but only once and the click doesn't work so it's not a pretty picture :(

Basically on click I need to draw #x_right and #x_left to 100% to form the X to close the menu and draw all the rest of the paths to 0% 

What am I doing wrong?

Thank you!

See the Pen xxKdZyK by gianpiero-di-lullo (@gianpiero-di-lullo) on CodePen

Link to comment
Share on other sites

The main thing that I'd change is moving the timeline animation outside of your hover and click states and make sure that the timeline is paused. If you just do that you can see your button start to work more like what you're expecting.


However, with multiple states affecting the same elements like you want, I think it makes sense to use one timeline for the whole thing but use a label as a kind of middle state to use on hover. Then when the element is clicked you "finish" the timeline and go backwards when it's clicked again or when it's unhovered. The opacity change (or whatever you'd like to do on hover of the clicked state) I would probably keep separate as it's affecting different properties.


I also changed one of your variable lists to make it fit with what you're trying to do, but you can shift elements around in whatever variables as you'd please.


This approach necessitates a variable to keep track of the clicked state, which I have added in the demo below:


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


Let me know if you have any questions about my approach and happy tweening!

  • Like 3
Link to comment
Share on other sites

10 minutes ago, jp_uk81 said:

Why did you add the label with addLabel()  (I didn't even know the existence of addLabel) and you didn't add it within the tween on line 9?

I assume that you mean adding it as the last parameter inside of the tween (the position parameter). There is a difference between creating a label (which is what I did using .addLabel()) and referring to a label (which is what I did in later tweens and the .tweenTo()). You want to add labels sometimes and refer to labels at other times.


For more information I suggest that you check out "Understanding the Position Parameter".


I hope that helps!

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