Jump to content
Search Community

How do i Animate it foreach link

FearMe4va test
Moderator Tag

Recommended Posts

Hi @FearMe4va, see the below example how to loop over all links and create mousenenter and mouseleave for each of them.

 

See the Pen RwrvdmW by ihatetomatoes (@ihatetomatoes) on CodePen

 

The example above works fine and also uses GSAP3 syntax instead of old GSAP2. 

 

const buttons = document.querySelectorAll('a');

buttons.forEach(button => {
  const letters = button.querySelectorAll('a span');
  
  // Timeline
  const tl = gsap.timeline({paused: true});
  tl.to(letters, {
    duration:1,
    color: 'black', 
    ease: Expo.easeOut,
    stagger: 0.02
  });

  // HOVER
  button.addEventListener("mouseenter", function(){
    tl.play();
  });
  button.addEventListener("mouseleave", function(){
    tl.reverse();
  });
  
});

Hope that helps with your GSAP question. The rest is only your CSS.

 

Happy tweening.

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