Jump to content
Search Community

Call a Greensock Timeline with JavaScript?

ericnguyen23 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

Hey Eric.

 

This is definitely possible! The setup depends on how you want it to animate. They key concept is that instead of adding a class, you'd use a tween to affect some properties of the drop down menu. Then when the menu/navigation has stopped being hovered, you tween it back to being hidden.

 

Is there a specific part of this process that you're having trouble with?

Link to comment
Share on other sites

4 minutes ago, ZachSaucier said:

Hey Eric.

 

This is definitely possible! The setup depends on how you want it to animate. They key concept is that instead of adding a class, you'd use a tween to affect some properties of the drop down menu. Then when the menu/navigation has stopped being hovered, you tween it back to being hidden.

 

Is there a specific part of this process that you're having trouble with?

 

Not yet, for now at least. 

I just wanted to verify this is possible. I'll go play with it now and if I have questions I'll come back.

Link to comment
Share on other sites

I'm back! 

I've edited/updated my codepen since I'm developing a React menu: 

 

So far, I've got the timeline to run (onLoad). Now how do I call it on mouseover and mouseleave? I've setup the mouseenter and mouseleave event handlers, but not sure how I'd go about calling the timeline. 

 

 

Link to comment
Share on other sites

Unfortunately I know nothing about react so I haven't even tried to work out what you intend with the useEffect function but this is a basic implementation of using paused:true on timeline and play and reverse in event handlers. Hopefully it will get you moving in the right direction.

 

See the Pen QeLXVj?editors=1010 by Visual-Q (@Visual-Q) on CodePen

  • Like 5
Link to comment
Share on other sites

16 hours ago, Visual-Q said:

Unfortunately I know nothing about react so I haven't even tried to work out what you intend with the useEffect function but this is a basic implementation of using paused:true on timeline and play and reverse in event handlers. Hopefully it will get you moving in the right direction.

 

 

 

 

I'm a noob in React myself, actually a relative noob in modern web dev, but seems like I have to use `useEffect` for animations to work with a functional component. 

 

This is what I was looking for, thanks! 

 

This is totally a side topic and not related to GSAP, but I'll throw it out there: How can I get my subnav to be positioned behind my main nav? 

Link to comment
Share on other sites

14 minutes ago, ZachSaucier said:

Take away the z-index of .nav. 

 

If you give it a z-index it will create its own stacking context, which prevents children from being placed behind it. See this post for more info.

 

Happy tweening!

 

Thanks Zach - although that works, it takes away the hovering functionality with subnav (because of the element below it). I'll look into more, hopefully I don't have to tear up my code too much! 

Link to comment
Share on other sites

I ended up taking all z-indexes out of play, even on subnav ( since a negative z-index limited me to a lot of functionality on that element) and positioned it absolute and animating visibility and height which achieved the effect I was looking for. 

 

GSAP is amazing!

 

See the Pen rXBgNR?editors=0110 by ericnguyen23 (@ericnguyen23) on CodePen

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