Community影像github.com

動畫分層與懸停微互動配方

為介面提供統一的節奏與一套精簡的懸停及狀態微互動詞彙:CSS 與 Motion 的持續時間分層(tap/pop/hover/card/layout)、互換交接、漸入高亮列、尾隨箭頭、V形指示器微調、不使用 translate 的卡片抬升、滾動邊緣淡出,以及複製與切換按鈕的圖示/標籤互換。

動畫分層與懸停微互動配方 是什麼?

這套技能提供了一個經過驗證的微互動系統,旨在解決產品中動畫不一致的問題。它圍繞兩個核心概念:持續時間應使用統一的層級體系(tap/pop/hover/card/layout),而非每個元件各自為政;懸停效果應柔和地改變幾何狀態,而不僅是顏色變化。支援的平台包括 CSS(Tailwind v4)、Framer Motion 以及 WAAPI,並提供了可直接使用的 React 元件,如 `IconSwap` 和 `LabelSwap`。透過內建的配方(如 hover-grow、trail、lift、scroll-fade)和詳盡的陷阱說明,開發者能快速導入一致的互動體驗,同時確保可訪問性(關注 `:focus-visible` 與 `prefers-reduced-motion`)與無障礙支援。

相容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/Adamparishspok/skills/tree/HEAD/skills/motion-and-hover-polish

Installed? Explore more 影像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

動畫分層與懸停配方

兩個在 17 個原型應用中驗證過的概念:

  1. 持續時間是一個尺度,而非每個元件的獨立數字。 眼睛將統一的節奏視為同一個產品。愈小的元件移動得愈快。
  2. 懸停柔和地移動幾何形狀。 一個逐漸填滿整行的高亮、一個抵達的箭頭、一個傾向於其去向的 V 形指示器、一個滾動至下一個狀態的標籤。僅有顏色變化的懸停看起來像在切換開關。

檔案

  • references/recipes.css:Tailwind v4 的 @theme 符號與 @utility 配方。
  • references/timing.ts:適用於 Motion 與 WAAPI 的同一組分層。
  • references/swap.tsx:IconSwap 與 LabelSwap(React)。

分層

分層毫秒適用場景
tap100圖示互換、按下動作
pop150選單、彈出視窗或工具提示開啟
hover200回應游標的列或控制項
card300卡片抬升、列表穩定、頁面切換
layout500面板收起、頁面重新排列
  • 進入時使用緩出曲線(cubic-bezier(0.22,1,0.36,1))。退出時使用緩入曲線,且持續時間縮短一層。
  • 當兩個元素互換位置時,移出的元素立即離開,移入的元素在 delay-handoff(50 毫秒)後開始。
  • 數值補間(計數器、進度條、圖表線條繪製)可持續更長時間,因為眼睛在跟隨資料。
  • 保留刻意使用的彈簧效果。

遷移方式:將每個隨意定義的持續時間對應到最接近的分層。

隨意定義的值分層
0.12tap
0.15–0.18pop
0.2–0.24hover
0.28–0.35card
0.4–0.5layout

預期螢幕上顯示的時序幾乎在所有地方變化不超過 20 毫秒。

配方(每個元素一個)

  • hover-grow(導航列、連結列):
    • 高亮是一個 ::before,初始時向內縮排(3px 6px)且透明,然後在淡入的同時擴展至整列。
    • 對於 :focus-visible、data-state=open 與 aria-current=page 也會顯示。
    • 正方形或粗獷主義設計(類似 Carbon)應改用平面高亮。
  • trail(連結列、「瀏覽方案」):
    • 一個尾隨字形,起初是半透明且縮小一半,直到父級 .group 被懸停或聚焦時,從其前緣開始放大。
    • trail-out(從左下角放大)加上 arrow-up-right 標記離開應用的連結。
  • nudge / nudge-back(V 形指示器、「檢視全部」、返回連結):朝目標方向傾斜 2px。
  • lift(可點擊卡片):
    • 表面提高一個亮度層級,陰影加深一個層級,持續時間為 card 層級。
    • 禁止使用 translate:在游標下移動的卡片會干擾瞄準。
  • scroll-fade(滾動面板):
    • 基於遮罩的邊緣淡出,僅在可滾動的一側顯示。由容器自身的滾動時間線驅動,不需要背景顏色。
    • 不支援的瀏覽器則不會顯示淡出效果。
  • IconSwap(選單轉關閉、複製轉勾選、太陽轉月亮):
    • 移出的字形縮小、傾斜 −22° 並以緩入曲線淡出。
    • 移入的字形在交接延遲後進入。
    • 兩者保持掛載狀態,以便在過渡過程中順利反向。
  • LabelSwap(「複製連結」轉「已複製」、「收起」轉「展開」):
    • 兩個標籤位於同一個網格儲存格中,因此不會有寬度跳動。
    • 隱藏的標籤透過 transition-discrete 設為 invisible,因此輔助技術只能聽到當前的標籤。

陷阱

  • 對自身有動畫的元素使用 scroll-fade(Radix 選單、彈出視窗或選取內容)會取代該元素的退出動畫。Radix 會等待一個永不結束的退出,導致選單保持開啟。請將淡出效果放在其內部的滾動子元素上。
  • scroll-fade 也會遮罩邊框和陰影。 不要將其放在有邊框的卡片上,應放在內部的滾動容器上。
  • Tailwind v4 中的自訂 duration-* 工具必須同時設定 --tw-duration,否則同一元素上的 transition-[…] 工具會根據排序順序勝出。
  • 帶有行高的具名型別步驟(--text-meta--line-height)在替換繼承了父級前導的任意尺寸時,會使每行轉換後偏移一個像素。中間步驟不應設定自己的行高。
  • 將懸停效果限制在 @media (hover: hover) 內。 在 :focus-visible 上顯示相同的狀態,並尊重 prefers-reduced-motion(Motion:<MotionConfig reducedMotion="user">)。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

Adamparishspok/skills

Make a website, web app or online store ready for AI agents. Scan it with Cloudflare's Agent Readiness checks, decide which checks apply to this kind of site, ship the discovery files and headers in priority order, and add the AI-first basics the scanner does not score (server-rendered content, JSON-LD, llms.txt). Covers robots.txt AI rules, Content Signals, sitemap, Markdown for Agents (Accept text/markdown), Link headers, API catalog, OAuth discovery, auth.md, MCP server card, A2A agent card, agent skills index, WebMCP, and commerce protocols (ACP, UCP, AP2, MPP, x402). Use when making a site AI-ready, agent-ready or AI-first, or fixing an isitagentready.com or Cloudflare Agent Readiness report. Triggers on: AI ready, agent ready, AI-first, agent readiness, isitagentready, AI Crawl Control, Markdown for Agents, text/markdown, llms.txt, GPTBot, ClaudeBot, AI crawlers, Content-Signal, ai-train, api-catalog, .well-known, oauth-protected-resource, auth.md, MCP server card, agent card, agent skills, WebMCP, a...

Adamparishspok/skills

Install a complete, lean favicon set on any website or web app — the five files modern browsers, iOS and Android actually use, one block of head markup added once in the root layout, and a check that every file resolves. Covers finding the public folder per framework, generating the set from one SVG (or from a RealFaviconGenerator package), dark-mode SVG icons, maskable manifest icons, cache busting and verification. Use when adding, replacing or auditing a favicon, app icon, apple-touch-icon or web manifest. Triggers on: favicon, favicon.ico, favicon.svg, apple-touch-icon, site.webmanifest, manifest.json, app icon, PWA icon, maskable icon, tab icon, RealFaviconGenerator.

Adamparishspok/skills

Consolidate several apps or prototypes onto one shared component library without flattening their looks. Covers finding duplicated local components (buttons, selects, fields, modals, pagers, toasts), making shared components token-sized so each suite or app sets its own measurements, mapping variant names, deciding what stays app-specific, and the tailwind-merge traps that silently break custom tokens. Use when several apps each grew their own Btn/Select/Modal, when a design system's components "don't fit" a second product, or when retheming a family of apps. Triggers on: shared component library, design system consolidation, duplicate components, retheme, suite of apps, shadcn retokened, token-driven components, cn tailwind-merge custom tokens, variant mapping.

Adamparishspok/skills

Build or migrate a UI's neutral palette (grounds, surfaces, lines, ink/text) as an OKLCH formula driven by a few inputs instead of dozens of hand-picked hex values, with light and dark themes, per-step ladder overrides, a fit script that reproduces existing colours, and a browser contrast audit. Use when creating a theme, adding dark mode, retinting a product, auditing text contrast, or consolidating several apps' palettes. Triggers on: palette, neutrals, grey ramp, dark mode, theme tokens, oklch, retint, hue, contrast audit, design tokens, Tailwind @theme colours.

相關技能