Communitygithub.com

微互動(UI 動畫)

當使用者要求「加入懸停/按壓效果」、「為切換開關或按鈕加入動畫」、「製作動態愛心按鈕」、「讓提示/快訊滑入」、「為抽屜或模態框加入動畫」、「為列表重新排序或新增/移除加入動畫」、「執行共享元素佈局轉場」或「優化 UI 回饋」時,應使用此技能。涵蓋使用 Framer Motion(motion/react)與現代 CSS 的 UI 動畫。

微互動(UI 動畫) 是什麼?

此技能專門處理微互動(UI Motion),亦即讓介面產生回應感與生命感的小型功能性動畫,例如懸停、按壓、焦點回饋、切換開關、提示訊息、抽屜、列表動畫及共享元素轉場。核心目標是提供即時回饋與連續性,而非純裝飾。技能涵蓋兩大主要實作路徑:使用 Framer Motion(套件名為 motion/react)的 React 開發者,以及希望透過現代 CSS 特性(如 @starting-style 與 transition-behavior: allow-discrete)達成無 JavaScript 動畫的開發者。技能明確規定動畫時長應落在 100–250 毫秒之間,並應僅動畫 transform 與 opacity 屬性以確保 GPU 合成效能。此外,技能強調尊重使用者的 prefers-reduced-motion 設定,並針對非必要動畫提供降級方案。針對交付與驗證,技能提供一個清晰的流程:建立一個獨立的 HTML 檔案,透過 ?state= 查詢參數凍結狀態,以利進行可重複的螢幕截圖與視覺回歸測試。此技能適用於 Claude Code、Cursor 及 Codex 等平台,文件中也包含參考檔案(如 framer-motion-recipes.md 與 css-recipes.md)以提供更深入的實作模式。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/nehakanjamala/personal_website/tree/HEAD/.agents/skills/micro-interaction

在你喜歡的 AI 中提問

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

說明文件

微互動(UI 動畫) 是做什麼的?

小型、功能性的動畫,讓介面感覺有回應且充滿生氣:懸停/按壓/焦點回饋、切換開關、提示訊息、抽屜以及列表/佈局動畫。目標是提供回饋與連續性,而非純裝飾。

使用時機

  • 懸停/按壓/焦點回饋;切換開關、核取方塊、愛心/按讚按鈕
  • 提示/快訊、抽屜、模態框、工具提示、手風琴(進入/離開)
  • 列表新增/移除/重新排序;共享元素(「魔法移動」)佈局轉場
  • 載入 → 成功 → 錯誤狀態轉換

原則(適用於所有情況)

  • 時長:UI 微互動的時長應在 100–250 毫秒。超過 ~400 毫秒會讓點擊回應感覺遲緩。
  • 只動畫 transform 與 opacity — 它們由 GPU 合成(不觸發佈局/繪製)。避免動畫 width/height/top/left;改用 scale 或佈局動畫。
  • 提供 即時 的按壓回饋: 在觸摸時以快速彈簧 scale: 0.96。
  • 非對稱時間:進入稍慢(ease-out),離開更快(ease-in)。事物應優雅地出現並迅速離去。
  • 尊重 prefers-reduced-motion: 限制非必要的動畫;保留透明度變化,減少大幅移動。
  • 預設緩動函數: ease-out 用於進入 cubic-bezier(0.16, 1, 0.3, 1);有品味的過衝效果為 cubic-bezier(0.34, 1.56, 0.64, 1);標準移動為 cubic-bezier(0.4, 0, 0.2, 1)。

Framer Motion(motion/react)核心

從 v11 開始,套件以 motion/react 匯入(framer-motion 這個名稱仍可運作)。

手勢與彈簧

import { motion } from "motion/react";

<motion.button
  whileHover={{ scale: 1.03 }}
  whileTap={{ scale: 0.96 }}
  whileFocus={{ boxShadow: "0 0 0 3px rgba(59,130,246,.5)" }}
  transition={{ type: "spring", stiffness: 400, damping: 30 }}
/>

彈簧直覺:stiffness 越高 = 越快;damping 越高 = 越少彈跳。stiffness: 400, damping: 30 是靈敏的 UI 預設值。若要明顯的彈跳,請降低 damping(例如 damping: 12)。

使用 AnimatePresence 進入 / 離開

離開動畫需要以 AnimatePresence 包覆條件渲染的子元素,每個子元素需有穩定的 key。

import { AnimatePresence, motion } from "motion/react";

<AnimatePresence>
  {open && (
    <motion.div
      key="panel"
      initial={{ opacity: 0, y: 8 }}
      animate={{ opacity: 1, y: 0 }}
      exit={{ opacity: 0, y: 8 }}
      transition={{ duration: 0.2, ease: [0.16, 1, 0.3, 1] }}
    />
  )}
</AnimatePresence>

對於提示/列表,請使用 mode="popLayout",以便被移除的項目在離開時不佔據空間。

佈局動畫(超級功能)

layout 會自動使用 transform 動畫任何佈局變化(位置/尺寸)— 非常適合重新排序、展開卡片和網格<->列表轉換。

<motion.li layout transition={{ type: "spring", stiffness: 500, damping: 40 }} />

跨元件的共享元素轉場:給兩個元素相同的 layoutId,當一個掛載而另一個卸載時,Framer Motion 會在其間進行動畫。

{!open && <motion.div layoutId="card" onClick={() => setOpen(true)} />}
<AnimatePresence>
  {open && <motion.div layoutId="card" />} {/* 「魔法移動」從來源位置開始 */}
</AnimatePresence>

陷阱:單純的 layout 元素會在縮放時扭曲 border-radius 和文字。請將 layout 加入應進行反向縮放的直接子元素,並偏好將 borderRadius/boxShadow 作為運動值,或使用 layout="position" 僅動畫位置。

純 CSS 路徑(無 JavaScript,包括離散屬性)

現代 CSS 無需函式庫即可動畫進入/離開甚至 display 切換。

.toast {
  transition: opacity 0.2s ease, transform 0.2s ease;
  /* 允許動畫到/從 display:none 以及初始渲染 */
  transition-behavior: allow-discrete;
}
.toast[hidden] { display: none; }

/* 在首次渲染 / 進入時,從這些值開始動畫 */
@starting-style {
  .toast { opacity: 0; transform: translateY(8px); }
}

@starting-style 定義了「開啟前」的值,以便元素在首次出現時以動畫方式進入;transition-behavior: allow-discrete 允許 display(以及彈出視窗/對話框的 overlay)參與,以便在元素被移除前執行離開動畫。Chrome/Edge/Safari 已支援;請為舊版瀏覽器提供無動畫的備援方案。

始終包含減少動畫的保護規則:

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

狀態,而非純裝飾

載入 → 成功 → 錯誤應是連續的動畫(例如按鈕從旋轉器變形為勾選標記),而非跳躍剪輯。保持元素掛載,並在狀態之間進行動畫,以便眼睛追蹤同一個物件。

交付與驗證(獨立 HTML)

打包助手(scripts/):scripts/seek-shot.sh anim.html 0 1.5 3 凍結 ?t=N 測試場景並對每個時刻截圖;scripts/contact-sheet.sh sheet.png frame-*.png 將它們拼接成一張圖以供快速審查。詳見 scripts/README.md。

對於自包含的互動展示(切換開關、愛心按鈕、提示、抽屜),交付物是一個可直接在瀏覽器中打開的 HTML 檔案。純 CSS 互動直接交付;對於 Framer Motion 展示,從 CDN(esm.sh)將 React + motion 載入到一個內聯模組中 — 無需建置步驟。單一檔案是合適的層級;不要使用打包工具。

輸出規範:

  • 一個 .html 檔案:你的標記,加上 CSS 轉場/@starting-style 或一個從 CDN 匯入 motion 的內聯 <script type="module">。
  • 一種到達最終靜止狀態以便截圖的方式 — 互動是由狀態驅動而非時間驅動,因此凍結狀態而非時鐘。

Seek 測試場景 — 鎖定確定性狀態。 微互動的「影格」是其狀態(閒置 / 懸停 / 按壓 / 開啟)。?state=open 在載入時應用目標狀態,以便截圖捕捉到靜止狀態:

<script>
  const s = new URLSearchParams(location.search).get("state");
  if (s) document.documentElement.dataset.state = s;   // CSS 根據 [data-state="open"] 設定樣式
  // Framer Motion:從 `s` 設定受控屬性(例如 const [open]=useState(s==="open"))
  // 如果是 CSS @keyframes 循環,則凍結它:el.style.animationDelay=(-N)+"s"; el.style.animationPlayState="paused";
  window.__ready = true;
</script>

驗證循環 — 渲染 → 設定狀態 → 截圖 → 檢查: 開啟每個有意義的狀態(?state=idle、?state=hover、?state=open),截圖,並檢查忠實度(按壓回饋感覺即時,離開動畫在卸載前執行)以及渲染瑕疵(layout 扭曲 border-radius/文字,提示在離開後仍佔據空間,FOUC,卡頓)。任何無頭工具皆可:

npx playwright screenshot --wait-for-timeout=400 "file://$PWD/demo.html?state=open" open.png

完成前請檢查:

  1. 可獨立開啟 — 無控制台錯誤,CDN React/motion(若使用)可解析。
  2. ?state=(或受控屬性)凍結能產出確定性、靜止的狀態。
  3. 跨狀態截圖 — 閒置 / 作用中 / 開啟 — 符合需求,無渲染瑕疵。
  4. prefers-reduced-motion 已遵守 — 大幅移動已移除,透明度/回饋保留。
  5. 緩動函數是有意為之 — 進入 ease-out,離開 ease-in,時長在 100–250 毫秒區間內。

快速參考

需求方法
按壓回饋whileTap={{ scale: 0.96 }} 彈簧 400/30
進入/離開AnimatePresence + initial/animate/exit
重新排序 / 調整大小layout 屬性(彈簧)
魔法移動共享 layoutId
提示堆疊AnimatePresence mode="popLayout"
無 JS 進入@starting-style + 轉場
動畫到 display:nonetransition-behavior: allow-discrete
無障礙性永遠加上 prefers-reduced-motion 保護規則

參考檔案

  • references/framer-motion-recipes.md — 變體 + 交錯、AnimatePresence 模式、layout/layoutId 魔法移動、Reorder 拖曳排序、拖曳約束、手勢組合以及 useReducedMotion。
  • references/css-recipes.md — @starting-style、transition-behavior: allow-discrete、彈出視窗/對話框離開動畫、關鍵影格旋轉器/切換、@property 可動畫自訂屬性以及 prefers-reduced-motion 模式。

Individual skills in this repo

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

nehakanjamala/personal_website

This skill should be used when the user asks to "fix janky CSS animation", "make animation 60fps", "stop layout thrashing", "animate width/height/top/left smoothly", "convert animation to transform", "animate box-shadow performantly", "animate height auto", "FLIP animation", or "why is my scroll/hover animation choppy".

nehakanjamala/personal_website

This skill should be used when the user asks to "respect prefers-reduced-motion", "honor reduced motion", "make my animations accessible", "fix vestibular / motion-sickness issues", "add a useReducedMotion hook", "gate GSAP / Framer Motion / Lenis for reduced motion", or "meet WCAG 2.3.3 / C39". Provides tiered (not all-or-nothing) reduced-motion patterns in CSS and JS.

nehakanjamala/personal_website

Create, modify, debug, and deploy Apify Actors, and write their input and output schemas. Use when building an Actor from scratch, changing or troubleshooting Actor code, generating or updating .actor schema files, or pushing an Actor to the Apify platform. To wrap an existing non-Actor project, use apify-actorization instead.

nehakanjamala/personal_website

Convert existing projects into Apify Actors - serverless cloud programs. Actorize JavaScript/TypeScript (SDK with Actor.init/exit), Python (async context manager), or any language (CLI wrapper). Use when migrating code to Apify, wrapping CLI tools as Actors, or adding Actor SDK to existing projects.

nehakanjamala/personal_website

Deprecated. Output schema generation moved to the apify-actor-development skill; prefer that skill whenever it is available.

nehakanjamala/personal_website

Design and build an official Apify integration for a company's product - workflow-automation apps (Zapier/n8n-style), AI agent plugins (coding-agent skills+MCP bundles or OpenClaw/Hermes-style harnesses), AI framework packages (LangChain/LlamaIndex-style), or direct application clients via apify-client. Use when planning, creating, or reviewing an integration that exposes Apify Actors, runs, datasets, or key-value stores inside another product.

nehakanjamala/personal_website

Universal AI-powered web scraper for any platform. Scrape data from Instagram, Facebook, TikTok, YouTube, LinkedIn, X/Twitter, Google Maps, Google Search, Google Trends, Reddit, Airbnb, Yelp, and 15+ more platforms. Use for lead generation, brand monitoring, competitor analysis, influencer discovery, trend research, content analytics, audience analysis, review analysis, SEO intelligence, recruitment, or any data extraction task.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a glassmorphism effect", "frosted glass UI", "Apple liquid glass style", "frosted blur card", "translucent glass panel animation", "make a frosted nav bar", "build a glass modal/dialog", "animate a glass card on hover", or "add a refracting liquid-glass hero". Covers frosted translucent panels with backdrop-filter blur, edge/specular highlights, SVG liquid-glass refraction, motion on hover/scroll/enter, and accessible reduced-transparency fallbacks.

nehakanjamala/personal_website

This skill should be used when the user asks to "build a scroll animation", "add ScrollTrigger", "pin a section while scrolling", "scrub an animation to scroll", "create a hero timeline", "do a horizontal scroll section", "split text and animate words", "animate a layout change with GSAP Flip", "sync ScrollTrigger with Lenis", "Lenis smooth scroll jittery", "ScrollTrigger markers drift", "ScrollTrigger pins break with Lenis/Locomotive", or "set up smooth scroll with GSAP pinning". Covers GSAP timelines, ScrollTrigger, SplitText, Flip, and Lenis/Locomotive smooth-scroll sync for code-driven web motion.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a Lottie animation", "play a .lottie or .json animation", "integrate a Bodymovin/After Effects animation on web or mobile", "control Lottie playback / segments", "make a scroll-driven Lottie", "recolor a Lottie at runtime", or "export an AE animation to Lottie". Covers dotLottie/lottie-web integration, playback control, interactivity, theming, and the AE export checklist.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate page or route transitions", "add a page transition or crossfade between views", "animate route changes in Next.js App Router", "use the View Transitions API", "AnimatePresence exit doesn't fire on navigation", or "Framer Motion exit animation not working / exit animation before unmount in Next.js". Covers enter/exit page-transition animation with the View Transitions API and Framer Motion, for Next.js App Router and general SPA routing.

nehakanjamala/personal_website

Scrape web pages using Scrapling with anti-bot bypass (like Cloudflare Turnstile), stealth headless browsing, spiders framework, adaptive scraping, and JavaScript rendering. Use when asked to scrape, crawl, or extract data from websites; web_fetch fails; the site has anti-bot protections; write Python code to scrape/crawl; or write spiders.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate an SVG", "make a line draw itself on", "do a stroke draw-on / signature animation", "morph one shape into another", "move an element along a path", "animate an icon/logo", or "animate an SVG gradient or filter". Covers stroke-dashoffset draw-on, path morphing, motion-along-path, and animated icons/gradients/filters via CSS, SMIL, and GSAP.

相關技能