Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jp_uk81

Hamburger menu with DrawSvg

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

Share this post


Link to post
Share on other sites

Are these the states that you're wanting?

 

1. Unhovered = three lines

2. Hovered = Hexagon

3. Clicked = X shape

 

If so, what happens when someone hovers it after it's been clicked?

Share this post


Link to post
Share on other sites

Hi Zach,

yes the states above are correct. I had in mind to lower the opacity or change colour of the X on hover but I didn't get that far yet

Thanks

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thank you Zach!

One question: 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?

 

thanks again

 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Just to clarify, you can add a label in the position parameter of a tween if it doesn't already exist. I personally find it easier to read by doing what Zach did with addLabel() or you can also just use .add("myLabel") too.

:)

 

  • Like 2

Share this post


Link to post
Share on other sites

That's clear. Thank you both!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×