Jump to content
Search Community

Tigger Timeline animations for multiple divs on hover

Cleo 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

Basically, Im trying to get an animation (#dd-heading) to trigger when the user hovers over  nav button(.dropdownmenu-button) that triggers dropdown with animation in it....

 

but it only seems to trigger the first div and the rest dont trigger.

 

Similar to this - https://www.open-wear.com/

 

//gsap animation of elements in dropdown navigation

 

  var toggle=0;
  var tldropdown = new TimelineMax({paused:true});
  var items = $('#dd-heading');
  var list = $('.dropdownmenu-button');

 

    tldropdown.staggerTo(items,  1.5, {x:20,opacity:1,delay:.5}, .5)
      .addPause(null,function(){ if(toggle)tldropdown.play(); } )
      .staggerTo(items, 1.5, {x:20,opacity:1}, .5)

 

  function over(){  tldropdown.restart(); toggle=0; }
  function out(){  tldropdown.play(); toggle=1; }

 

  list.hover(over, out);

Link to comment
Share on other sites

Welcome to the forums, @Cleo

 

It's kinda tough to troubleshoot blind (a codepen would be super helpful) but it looks like your "items" only consists of one element with the ID of dd-heading. So perhaps your selector is wrong? Again, I don't know how you set up your HTML, so it's difficult to diagnose. Remember, though, you're not supposed to use the same ID for multiple elements (they must be unique). Did you mean to use a class instead maybe? 

 

Also, in your out(), you're simply playing the timeline which probably isn't the best idea because what happens if someone rolls their mouse over...and then very quickly rolls out (before 1.5 seconds has elapsed to reach the pause)? Nothing would happen. The animation would just keep playing. In order to get that out() animation to play, they'd be forced to wait the full 1.5 seconds before rolling out. That's just a logic issue with your code, not a GSAP thing. 

 

Maybe it'd be simpler to just build an animation in the over() and a different one in the out() so that they can dynamically determine their starting values based on whatever the properties are at that moment (even if a previous animation is part-way finished). 

 

If you still need some help, it'd be awesome if you could provide just the simplest codepen that demonstrates what you're attempting. 

 

Happy tweening!

 

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