Jump to content
Search Community

Menu animation only triggering on second click

Waiz test
Moderator Tag

Recommended Posts

Good Moring everyone

I have this little GSAP function that i wrote to open and close menu on click but the animation only work on second click, i have searched every where none of the provided solution works for me

 

export function toggleVisibility(targetRef: React.RefObject<HTMLElement>) {
  const target = targetRef.current!;

  if (target) {
    const tl = gsap.timeline();
    tl.to(target, {
      autoAlpha: target.style?.opacity === '0' ? 1 : 0,
      duration: 0.5,
      ease: 'power1.easeInOut',
    })
    .fromTo(
      target,
      {
        y: 20,
        scale: 1.2,
      },
      {
        y: 0,
        scale: 1,
        boxShadow: 'none',
        duration: 0.5,
        ease: 'elastic.out(2, 0.3)',
      }
    );
  }
}

 

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