悬停时的 Tailwind Css 自定义动画

时间:2021-06-28 20:45:36

标签: animation hover tailwind-css

我用顺风创建了一个眼睛图标动画,但是我无法在悬停时制作它:(你能指导我如何在悬停时制作动画吗?:)

Tailwind Eye-Icon-Animation

感谢您的帮助!!

1 个答案:

答案 0 :(得分:0)

在您的配置中扩展 animation 以支持 hovergroup-hover 变体

<div class="h-36 w-36 mx-auto flex justify-center items-center group hover:animate-roll">
  <div class="h-full w-full bg-black transform rotate-45 border-radius-eye flex justify-center items-center"> </div>
  <div class="h-12 w-12  bg-white rounded-full z-10 absolute group-hover:animate-movement" ></div>
</div>

tailwind.config.js

const colors = require('tailwindcss/colors')

module.exports = {
  theme: {
    extend: {
      keyframes: {
      roll: { 
          '0%, 10%, 20%, 30%, 40%, 60%, 70%, 80%, 90%, 100%': { transform: 'scale(1)'},
          '50%': { transform: 'scaleY(0)' }
        },

        movement: {
          '0%, 20%, 40%, 60%, 80%, 100%': { transform: 'translateX(0rem)' },
          '10%': { transform: 'translateX(2rem)' },
          '30%': { transform: 'translateX(-2rem)' },
          '50%': { transform: 'translateY(1rem)' },
          '70%': { transform: 'translateY(-1rem)' },
        }

      },
      animation: {
        roll: 'roll 3s infinite ',
        movement: 'movement 5s infinite'
      },
    },
  },
  variants: {
    extend: {
      animation: ['hover', 'group-hover'] 
    }
  },
  plugins: [],
}

注意:当您的父元素具有 flex 类时,它具有全宽意味着在整行(不仅是眼睛)悬停时发生悬停效果。为了防止它,我将 h-36w-36 从“眼睛”重新定位到包装器并添加 mx-auto 使其居中