Communitygithub.com

微交互(UI动效)

该技能用于处理悬停/按压效果、开关动画、点赞按钮、弹窗滑动、抽屉/模态框动效、列表重排或添加/删除动画、共享元素布局过渡,以及UI反馈优化。涵盖Framer Motion(motion/react)和现代CSS。

微交互(UI动效) 是什么?

该技能专注于实现小型、功能性的界面动效,旨在让界面响应更快速、更具生命力,包括悬停/按压/聚焦反馈、开关切换、弹窗、抽屉以及列表和布局动画。其核心目标是提供反馈和连续性,而非装饰。该技能适用于Framer Motion(motion/react)和纯CSS两种路径,并提供了详细的原则和实现模式,例如动效时长控制在100-250ms之间,优先动画化`transform`和`opacity`,以及遵守`prefers-reduced-motion`无障碍设计。技能还涵盖了使用`AnimatePresence`实现进入/退出动画、使用`layout`属性实现共享元素过渡、以及使用现代CSS的`@starting-style`和`transition-behavior: allow-discrete`实现无需JavaScript的动画。最后,该技能提供了完整的交付与验证流程,包括生成独立HTML文件、使用`?state=`参数冻结状态进行截图验证,以及检查动效保真度和常见问题。

兼容平台~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–250ms 之间。任何超过约400ms的时长在点击响应中都会显得滞后。
  • 仅对 transform 和 opacity 进行动画——它们由GPU合成(不触发布局/绘制)。避免对 width/height/top/left 进行动画;改用 scale 或布局动画。
  • 提供 即时 按压反馈:按下时 scale: 0.96,配合快速弹簧动画。
  • 不对称时间:进入稍慢(缓出),退出更快(缓入)。元素应优雅地出现并迅速离开。
  • 尊重 prefers-reduced-motion:限制非必要的动效;保留透明度变化,减少大幅度移动。
  • 缓动默认值:进入使用缓出 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: 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 harness 并截取每个时刻的截图;scripts/contact-sheet.sh sheet.png frame-*.png 将它们拼贴在一起以便一目了然的审查。详见 scripts/README.md。

对于自包含的交互演示(开关、点赞按钮、弹窗、抽屉),交付物是一个可以直接在浏览器中打开的HTML文件。纯CSS交互直接交付;对于Framer Motion演示,通过CDN(esm.sh)将React + motion 加载到一个内联模块中——无需构建步骤。一个文件是合适的层级;不要使用打包工具。

输出约定:

  • 一个 .html 文件:你的标记,加上CSS过渡/@starting-style 或一个内联 <script type="module"> 从CDN导入 motion。
  • 一种用于截图定位到已解决的结束状态的方法——交互是状态驱动的,而非时间驱动,所以冻结状态而不是时钟。

Seek harness — 固定一个确定的状态。 微交互的“帧”是其状态(空闲/悬停/按下/打开)。?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. 缓动是经过设计的——进入缓出,退出缓入,时长在100–250ms范围内。

快速参考

需求方法
按压反馈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.

相关技能