hover的时候,悬浮框从下往上,从隐藏到显示出现

要实现悬浮框从下往上,从隐藏到显示的效果,可以使用 Tailwind CSS 提供的 transform 和 transition 工具类。

HTML 结构:

<div class="relative group">
  <button class="bg-blue-500 text-white px-4 py-2 rounded">
    Hover me
  </button>
  <div class="absolute bottom-0 left-0 w-64 bg-white shadow-lg rounded-lg p-4 transform translate-y-full group-hover:translate-y-0 transition-transform duration-300 ease-in-out">
    <h3 class="text-lg font-bold mb-2">Tooltip Content</h3>
    <p>This is the content that will be displayed in the tooltip.</p>
  </div>
</div>

CSS 解释:

relative group: 给包裹整个元素的容器添加 relative 定位,并添加 group 类用于 hover 状态的选择。
absolute bottom-0 left-0: 将悬浮框定位在容器的底部左侧。
w-64 bg-white shadow-lg rounded-lg p-4: 设置悬浮框的样式,包括宽度、背景色、阴影、圆角和内边距。
transform translate-y-full: 将悬浮框初始位置设置为向下完全隐藏的位置。
group-hover:translate-y-0: 当容器被 hover 时,将悬浮框的位置设置为向上完全显示的位置。
transition-transform duration-300 ease-in-out: 添加 300ms 的 transform 过渡动画,使用 ease-in-out 的缓动函数实现平滑的动画效果。
通过这种方式,当用户将鼠标悬停在按钮上时,悬浮框会从下方向上滑动显示出来,从隐藏到完全显示的过程会有一个平滑的动画效果。当鼠标离开时,悬浮框会自动向下隐藏。

你可以根据实际需求调整悬浮框的大小、位置、样式等属性,并根据设计稿来微调过渡动画的时间和缓动函数,以达到理想的效果。

本文链接:

https://xiaopanglian.com/archives/71.html
1 + 6 =
快来做第一个评论的人吧~