果冻按钮

悬停时按钮像被戳了一下的果冻,挤压、拉伸,晃几下再停稳。

  • CSS
  • 按钮
  • 悬停
  • 收录于

AI 提示词

用纯 CSS 制作果冻晃动按钮。在 :hover 和 :focus-visible 时播放一次 700ms 的 keyframe 动画,交替使用非等比缩放:0% scale(1,1)、30% scale(1.2,0.8)、40% scale(0.8,1.2)、50% scale(1.1,0.9)、65% scale(0.95,1.05)、75% scale(1.03,0.97)、100% scale(1,1)。使用 ease 缓动,每次晃动都比上一次小,呈现弹性感。文字保持居中,避免被裁切。在 prefers-reduced-motion 下用背景色变化代替晃动。按钮文字为“立即开玩”。

源代码

Demo.tsx
'use client'

import s from './demo.module.css'

export default function JellyButton({ labels }: { labels: Record<string, string> }) {
  return (
    <button type="button" className={s.button}>
      {labels.cta}
    </button>
  )
}
demo.module.css
.button {
  height: 52px;
  padding: 0 32px;
  border: 0;
  border-radius: var(--radius-sm);
  font: 500 var(--text-base) / 1 var(--font-body);
  white-space: nowrap;
  cursor: pointer;
  border-radius: 999px;
  background: var(--stage-accent);
  color: var(--stage-accent-ink);
  font-weight: 600;
}

.button:hover,
.button:focus-visible {
  animation: jelly 700ms ease;
}

.button:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 4px; }

@keyframes jelly {
  0%, 100% { transform: scale(1, 1); }
  30% { transform: scale(1.2, 0.8); }
  40% { transform: scale(0.8, 1.2); }
  50% { transform: scale(1.1, 0.9); }
  65% { transform: scale(0.95, 1.05); }
  75% { transform: scale(1.03, 0.97); }
}

@media (prefers-reduced-motion: reduce) {
  .button:hover, .button:focus-visible { animation: none; background: var(--stage-accent-hover); }
}

投稿创意

看到想收录的动效或主题?简单描述一下,会打开一个预先填好的 GitHub Issue,确认后即可提交。

你想投稿的是?

需要 GitHub 账号,投稿内容会公开。