npx skills add https://github.com/secondsky/claude-skills --skill motionMotion(包名:motion,原名 framer-motion)是行业标准的 React 动画库,已被数千个生产环境应用所采用。拥有超过 30,200 个 GitHub star 和 300 多个官方示例,它提供了一个声明式 API,可以用最少的代码创建复杂的动画。
核心能力:
生产环境测试:React 19、Next.js 15、Vite 6、Tailwind v4
复杂交互:
基于滚动的动画:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
布局过渡:
高级功能:
包优化:
auto-animate:3.28 KB 对比 34 KB)framer-motion v12.23.24 变通方案 - 参见已知问题)bun add motion # 推荐
# 或:npm install motion
# 或:yarn add motion
当前版本:12.23.24(验证于 2025-11-07)
Cloudflare Workers 的替代方案:
# 如果部署到 Cloudflare Workers,请使用 framer-motion
bun add framer-motion
# 或:npm install framer-motion
motion 组件:约 34 KB(压缩+gzip)LazyMotion + m 组件:约 4.6 KBuseAnimate mini:2.3 KB(最小的 React 动画库)useAnimate hybrid:17 KBmotion 组件将任何 HTML/SVG 元素转换为可动画的组件:
import { motion } from "motion/react"
// 基础动画
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
内容淡入并向上滑动
</motion.div>
// 手势控制
<motion.button
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.95 }}
>
点击我
</motion.button>
属性:
initial:起始状态(对象或变体名称)animate:目标状态(对象或变体名称)exit:卸载状态(需要 AnimatePresence)transition:时序/缓动配置whileHover、whileTap、whileFocus:手势状态whileInView:视口触发的动画drag:启用拖拽("x"、"y" 或 true 表示两者)layout:启用 FLIP 布局动画命名的动画状态,可在组件树中传播:
const variants = {
hidden: { opacity: 0, y: 20 },
visible: { opacity: 1, y: 0 }
}
<motion.div variants={variants} initial="hidden" animate="visible">
内容
</motion.div>
对于高级编排(staggerChildren、delayChildren、动态变体),请加载 references/core-concepts-deep-dive.md。
在组件卸载时启用动画:
import { AnimatePresence } from "motion/react"
<AnimatePresence>
{isVisible && (
<motion.div
key="modal"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
模态内容
</motion.div>
)}
</AnimatePresence>
关键规则:
key 属性常见错误(退出动画不会播放):
// ❌ 错误 - AnimatePresence 随条件卸载
{isVisible && (
<AnimatePresence>
<motion.div>内容</motion.div>
</AnimatePresence>
)}
// ✅ 正确 - AnimatePresence 保持挂载
<AnimatePresence>
{isVisible && <motion.div key="unique">内容</motion.div>}
</AnimatePresence>
自动动画化布局变化:
<motion.div layout>
{isExpanded ? <FullContent /> : <Summary />}
</motion.div>
特殊属性:layoutId(共享元素过渡)、layoutScroll(可滚动容器)、layoutRoot(固定定位)。
对于高级模式(LayoutGroup、layoutId 编排),请加载 references/core-concepts-deep-dive.md。
// 视口触发
<motion.div
initial={{ opacity: 0, y: 50 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true }}
>
进入视口时淡入
</motion.div>
// 滚动关联(视差)
import { useScroll, useTransform } from "motion/react"
const { scrollYProgress } = useScroll()
const y = useTransform(scrollYProgress, [0, 1], [0, -300])
<motion.div style={{ y }}>视差效果</motion.div>
对于高级滚动模式(useScroll 偏移量、useTransform 缓动、视差图层),请加载 references/core-concepts-deep-dive.md。
<motion.div drag="x" dragConstraints={{ left: -200, right: 200 }}>
拖拽我
</motion.div>
可用:whileHover、whileTap、whileFocus、whileDrag、whileInView、drag。
对于高级拖拽控制(动量、弹性、事件处理器),请加载 references/core-concepts-deep-dive.md。
<motion.div
animate={{ x: 100 }}
transition={{ type: "spring", stiffness: 100, damping: 10 }}
/>
常用预设:弹跳 { stiffness: 300, damping: 10 },平滑 { stiffness: 100, damping: 20 }。
对于弹簧调优(质量、可视化工具、预设),请加载 references/core-concepts-deep-dive.md。
Vite:bun add motion → import { motion } from "motion/react"(开箱即用)
Next.js App Router:需要 "use client" 指令或客户端组件包装器
"use client"
import { motion } from "motion/react"
Tailwind:⚠️ 移除 transition-* 类(会导致与 Motion 动画冲突)
Cloudflare Workers:改用 framer-motion v12.23.24(Motion 存在 Wrangler 构建问题)
对于完整的集成指南(Next.js 模式、SSR、框架特定问题),请加载 references/nextjs-integration.md。
包大小:使用 LazyMotion(34 KB → 4.6 KB):
import { LazyMotion, domAnimation, m } from "motion/react"
<LazyMotion features={domAnimation}>
<m.div>仅 4.6 KB!</m.div>
</LazyMotion>
大型列表:对于 50 个以上的动画项目,使用虚拟化(react-window、react-virtuoso)。
对于完整的优化指南(硬件加速、内存分析、生产环境基准测试),请加载 references/performance-optimization.md。
尊重 prefers-reduced-motion:
import { MotionConfig } from "motion/react"
<MotionConfig reducedMotion="user">
<App />
</MotionConfig>
键盘支持:使用 whileFocus 实现键盘触发的动画。
<motion.button whileFocus={{ scale: 1.1 }} tabIndex={0}>
键盘可访问
</motion.button>
对于完整的可访问性指南(ARIA 模式、屏幕阅读器、AnimatePresence 变通方案、测试),请加载 references/accessibility-guide.md。
模态对话框(AnimatePresence + 背景):
<AnimatePresence>
{isOpen && (
<motion.dialog exit={{ opacity: 0 }}>内容</motion.dialog>
)}
</AnimatePresence>
手风琴(高度动画):
<motion.div animate={{ height: isOpen ? "auto" : 0 }}>
内容
</motion.div>
对于 15 个以上的生产环境模式(轮播、标签页、滚动显现、视差、通知),请加载 references/common-patterns.md。
症状:组件瞬间消失,没有退出动画。
解决方案:AnimatePresence 必须保持挂载,包裹条件语句(而不是被条件语句包裹):
// ❌ 错误
{isVisible && <AnimatePresence><motion.div>内容</motion.div></AnimatePresence>}
// ✅ 正确
<AnimatePresence>
{isVisible && <motion.div key="unique">内容</motion.div>}
</AnimatePresence>
症状:构建失败,提示 "motion is not defined" 或 SSR 错误。
解决方案:添加 "use client" 指令:
"use client"
import { motion } from "motion/react"
症状:动画卡顿或不工作。
解决方案:移除 transition-* 类(Motion 会覆盖 CSS 过渡):
// ❌ 错误:<motion.div className="transition-all" animate={{ x: 100 }} />
// ✅ 正确:<motion.div animate={{ x: 100 }} />
症状:使用 motion 包时 Wrangler 构建失败。
解决方案:改用 framer-motion v12.23.24(GitHub issue #2918):
bun add framer-motion # 相同的 API,适用于 Workers
症状:50-100 个以上的动画项目导致严重减速。
解决方案:使用虚拟化(react-window、react-virtuoso)。
对于 5 个以上的其他问题(layoutScroll、layoutRoot、AnimatePresence + layoutId),请加载 references/nextjs-integration.md 或 references/core-concepts-deep-dive.md。
Claude 应根据用户需求加载这些参考文档:
references/core-concepts-deep-dive.md:references/performance-optimization.md:references/nextjs-integration.md:references/accessibility-guide.md:references/common-patterns.md:references/motion-vs-auto-animate.md:此技能在 templates/ 目录中包含 5 个生产就绪的模板:
将模板复制到您的项目中并根据需要进行自定义。
此技能包含 4 个全面的参考指南:
详细指南请参见 references/ 目录。
此技能包含 2 个自动化脚本:
自动化工具请参见 scripts/ 目录。
相关技能:auto-animate(简单列表)、tailwind-v4-shadcn(样式)、nextjs(App Router)、cloudflare-worker-base
Motion 与 AutoAnimate 对比:加载 references/motion-vs-auto-animate.md 获取详细对比。
令牌节省:约 83%(30k → 5k 令牌) | 错误预防:100%(29+ 个错误) | 时间节省:约 85%(2-3 小时 → 20-30 分钟)
| 包 | 版本 | 状态 |
|---|---|---|
| motion | 12.23.24 | ✅ 最新稳定版 |
| framer-motion | 12.23.24 | ✅ Cloudflare 的替代方案 |
| react | 19.2.0 | ✅ 最新稳定版 |
| vite | 6.0.0 | ✅ 最新稳定版 |
发现问题或有建议?
生产环境测试:✅ React 19 + Next.js 15 + Vite 6 + Tailwind v4 令牌节省:约 83% 错误预防:100%(29+ 个已记录的错误被预防) 包大小:2.3 KB(mini)- 34 KB(完整版),使用 LazyMotion 可优化至 4.6 KB 可访问性:MotionConfig reducedMotion 支持 准备就绪! 使用 ./scripts/install-skill.sh motion 安装
每周安装
161
仓库
GitHub Stars
90
首次出现
2026年1月25日
安全审计
安装于
opencode139
gemini-cli139
codex137
cursor137
github-copilot134
claude-code134
Motion (package: motion, formerly framer-motion) is the industry-standard React animation library used in production by thousands of applications. With 30,200+ GitHub stars and 300+ official examples, it provides a declarative API for creating sophisticated animations with minimal code.
Key Capabilities:
Production Tested : React 19, Next.js 15, Vite 6, Tailwind v4
Complex Interactions :
Scroll-Based Animations :
Layout Transitions :
Advanced Features :
Bundle Optimization :
auto-animate instead: 3.28 KB vs 34 KB)framer-motion v12.23.24 workaround - see Known Issues)bun add motion # preferred
# or: npm install motion
# or: yarn add motion
Current Version : 12.23.24 (verified 2025-11-07)
Alternative for Cloudflare Workers :
# Use framer-motion if deploying to Cloudflare Workers
bun add framer-motion
# or: npm install framer-motion
motion component: ~34 KB minified+gzippedLazyMotion + m component: ~4.6 KBuseAnimate mini: 2.3 KB (smallest React animation library)useAnimate hybrid: 17 KBmotion ComponentTransform any HTML/SVG element into an animatable component:
import { motion } from "motion/react"
// Basic animation
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
Content fades in and slides up
</motion.div>
// Gesture controls
<motion.button
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.95 }}
>
Click me
</motion.button>
Props:
initial: Starting state (object or variant name)animate: Target state (object or variant name)exit: Unmounting state (requires AnimatePresence)transition: Timing/easing configurationwhileHover, whileTap, whileFocus: Gesture stateswhileInView: Viewport-triggered animationdrag: Enable dragging ("x", "y", or true for both)layout: Enable FLIP layout animationsNamed animation states that propagate through component tree:
const variants = {
hidden: { opacity: 0, y: 20 },
visible: { opacity: 1, y: 0 }
}
<motion.div variants={variants} initial="hidden" animate="visible">
Content
</motion.div>
For advanced orchestration (staggerChildren, delayChildren, dynamic variants), load references/core-concepts-deep-dive.md.
Enables animations when components unmount:
import { AnimatePresence } from "motion/react"
<AnimatePresence>
{isVisible && (
<motion.div
key="modal"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
Modal content
</motion.div>
)}
</AnimatePresence>
Critical Rules:
key propsCommon Mistake (exit animation won't play):
// ❌ Wrong - AnimatePresence unmounts with condition
{isVisible && (
<AnimatePresence>
<motion.div>Content</motion.div>
</AnimatePresence>
)}
// ✅ Correct - AnimatePresence stays mounted
<AnimatePresence>
{isVisible && <motion.div key="unique">Content</motion.div>}
</AnimatePresence>
Automatically animate layout changes:
<motion.div layout>
{isExpanded ? <FullContent /> : <Summary />}
</motion.div>
Special props : layoutId (shared element transitions), layoutScroll (scrollable containers), layoutRoot (fixed positioning).
For advanced patterns (LayoutGroup, layoutId orchestration), load references/core-concepts-deep-dive.md.
// Viewport-triggered
<motion.div
initial={{ opacity: 0, y: 50 }}
whileInView={{ opacity: 1, y: 0 }}
viewport={{ once: true }}
>
Fades in when entering viewport
</motion.div>
// Scroll-linked (parallax)
import { useScroll, useTransform } from "motion/react"
const { scrollYProgress } = useScroll()
const y = useTransform(scrollYProgress, [0, 1], [0, -300])
<motion.div style={{ y }}>Parallax effect</motion.div>
For advanced scroll patterns (useScroll offsets, useTransform easing, parallax layers), load references/core-concepts-deep-dive.md.
<motion.div drag="x" dragConstraints={{ left: -200, right: 200 }}>
Drag me
</motion.div>
Available : whileHover, whileTap, whileFocus, whileDrag, whileInView, drag.
For advanced drag controls (momentum, elastic, event handlers), load references/core-concepts-deep-dive.md.
<motion.div
animate={{ x: 100 }}
transition={{ type: "spring", stiffness: 100, damping: 10 }}
/>
Common presets : Bouncy { stiffness: 300, damping: 10 }, Smooth { stiffness: 100, damping: 20 }.
For spring tuning (mass, visualizer, presets), load references/core-concepts-deep-dive.md.
Vite : bun add motion → import { motion } from "motion/react" (works out of the box)
Next.js App Router : Requires "use client" directive or client component wrapper
"use client"
import { motion } from "motion/react"
Tailwind : ⚠️ Remove transition-* classes (causes conflicts with Motion animations)
Cloudflare Workers : Use framer-motion v12.23.24 instead (Motion has Wrangler build issues)
For complete integration guides (Next.js patterns, SSR, framework-specific issues), load references/nextjs-integration.md.
Bundle Size : Use LazyMotion (34 KB → 4.6 KB):
import { LazyMotion, domAnimation, m } from "motion/react"
<LazyMotion features={domAnimation}>
<m.div>Only 4.6 KB!</m.div>
</LazyMotion>
Large Lists : Use virtualization (react-window, react-virtuoso) for 50+ animated items.
For complete optimization guide (hardware acceleration, memory profiling, production benchmarks), load references/performance-optimization.md.
Respectprefers-reduced-motion:
import { MotionConfig } from "motion/react"
<MotionConfig reducedMotion="user">
<App />
</MotionConfig>
Keyboard Support : Use whileFocus for keyboard-triggered animations.
<motion.button whileFocus={{ scale: 1.1 }} tabIndex={0}>
Keyboard accessible
</motion.button>
For complete accessibility guide (ARIA patterns, screen readers, AnimatePresence workaround, testing), load references/accessibility-guide.md.
Modal Dialog (AnimatePresence + backdrop):
<AnimatePresence>
{isOpen && (
<motion.dialog exit={{ opacity: 0 }}>Content</motion.dialog>
)}
</AnimatePresence>
Accordion (height animation):
<motion.div animate={{ height: isOpen ? "auto" : 0 }}>
Content
</motion.div>
For 15+ production patterns (carousel, tabs, scroll reveal, parallax, notifications), load references/common-patterns.md.
Symptom : Components disappear instantly without exit animation.
Solution : AnimatePresence must stay mounted, wrap the conditional (not be wrapped by it):
// ❌ Wrong
{isVisible && <AnimatePresence><motion.div>Content</motion.div></AnimatePresence>}
// ✅ Correct
<AnimatePresence>
{isVisible && <motion.div key="unique">Content</motion.div>}
</AnimatePresence>
Symptom : Build fails with "motion is not defined" or SSR errors.
Solution : Add "use client" directive:
"use client"
import { motion } from "motion/react"
Symptom : Animations stutter or don't work.
Solution : Remove transition-* classes (Motion overrides CSS transitions):
// ❌ Wrong: <motion.div className="transition-all" animate={{ x: 100 }} />
// ✅ Correct: <motion.div animate={{ x: 100 }} />
Symptom : Wrangler build fails when using motion package.
Solution : Use framer-motion v12.23.24 instead (GitHub issue #2918):
bun add framer-motion # Same API, works with Workers
Symptom : 50-100+ animated items cause severe slowdown.
Solution : Use virtualization (react-window, react-virtuoso).
For 5+ additional issues (layoutScroll, layoutRoot, AnimatePresence + layoutId), load references/nextjs-integration.md or references/core-concepts-deep-dive.md.
Claude should load these references based on user needs:
references/core-concepts-deep-dive.md when:references/performance-optimization.md when:references/nextjs-integration.md when:references/accessibility-guide.md when:references/common-patterns.md when:references/motion-vs-auto-animate.md when:This skill includes 5 production-ready templates in the templates/ directory:
Copy templates into your project and customize as needed.
This skill includes 4 comprehensive reference guides:
See references/ directory for detailed guides.
This skill includes 2 automation scripts:
See scripts/ directory for automation tools.
Related Skills : auto-animate (simple lists), tailwind-v4-shadcn (styling), nextjs (App Router), cloudflare-worker-base
Motion vs AutoAnimate : Load references/motion-vs-auto-animate.md for detailed comparison.
Token Savings : ~83% (30k → 5k tokens) | Error Prevention : 100% (29+ errors) | Time Savings : ~85% (2-3 hrs → 20-30 min)
| Package | Version | Status |
|---|---|---|
| motion | 12.23.24 | ✅ Latest stable |
| framer-motion | 12.23.24 | ✅ Alternative for Cloudflare |
| react | 19.2.0 | ✅ Latest stable |
| vite | 6.0.0 | ✅ Latest stable |
Found an issue or have a suggestion?
Production Tested : ✅ React 19 + Next.js 15 + Vite 6 + Tailwind v4 Token Savings : ~83% Error Prevention : 100% (29+ documented errors prevented) Bundle Size : 2.3 KB (mini) - 34 KB (full), optimizable to 4.6 KB with LazyMotion Accessibility : MotionConfig reducedMotion support Ready to use! Install with ./scripts/install-skill.sh motion
Weekly Installs
161
Repository
GitHub Stars
90
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode139
gemini-cli139
codex137
cursor137
github-copilot134
claude-code134
TanStack Query v5 完全指南:React 数据管理、乐观更新、离线支持
2,500 周安装