尝试在Next.js 13和Tailwind中使用GSAP创建悬停动画。

huangapple go评论85阅读模式
英文:

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

问题

我正在使用Next.js 13(TypeScript)、Tailwind和GSAP制作网站,想知道是否可以制作类似于附图中的动画效果(抱歉我的绘画技巧不太好)。尝试在Next.js 13和Tailwind中使用GSAP创建悬停动画。

这不是一个按钮,只是一个装饰词,在悬停时会更改为具有不同样式的另一个词。

英文:

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). 尝试在Next.js 13和Tailwind中使用GSAP创建悬停动画。

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

答案1

得分: 1

这使用了带有溢出隐藏和平移的网格布局,是纯CSS的解决方案。

<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>很棒</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">好</span></div>
</div>

链接: https://play.tailwindcss.com/J45fD2mYLA

英文:

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

&lt;div class=&quot;group m-5 grid h-10 w-20 cursor-pointer grid-cols-2 overflow-hidden rounded-lg border-2 border-orange-400&quot;&gt;
  &lt;div class=&quot;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&quot;&gt;&lt;span&gt;GREAT&lt;/span&gt;&lt;/div&gt;
  &lt;div class=&quot;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&quot;&gt;&lt;span class=&quot;block w-20 py-2 text-center&quot;&gt;GOOD&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;

https://play.tailwindcss.com/J45fD2mYLA

huangapple
  • 本文由 发表于 2023年7月13日 15:27:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定