typescriptanimationnext.jstailwind-cssgsap

Trying to make a hover animation with GSAP in nextjs 13 and tailwind


I'm making a website with Nextjs 13 (TypeScript), tailwind and GSAP, I was wondering if it's possible to make some kind of animation like in the screenshot enclosed (sorry for my great paint skills). desired hover effect

is not a button, is just a decoration word that will change on hover for another with different style.


Solution

  • This uses a grid layout with overflow hidden and translate for a CSS only solution.

    <div class="group m-5 grid h-10 w-20 cursor-pointer grid-cols-2 overflow-hidden rounded-lg border-2 border-orange-400">
      <div class="grid h-10 w-20 -translate-x-full -translate-y-[2px] place-content-center rounded-lg border-2 border-orange-400 bg-orange-400 text-center font-bold text-white transition-transform duration-500 group-hover:translate-x-0"><span>GREAT</span></div>
      <div class="h-10 -translate-x-full -translate-y-[2px] rounded-lg border-orange-400 font-bold text-orange-400 transition-transform duration-500 group-hover:translate-x-full"><span class="block w-20 py-2 text-center">GOOD</span></div>
    </div>
    

    https://play.tailwindcss.com/J45fD2mYLA