SuperAPI AI 工具集

framer-motion

前端与建站

查看项目

更新于 10-16 08:10

技能介绍

用途:为 React 项目提供 Framer Motion 动效库的专家知识,用于实现声明式动画、手势识别与布局动画,并兼顾性能。

主要能力:

  • Motion 组件:以 motion. 前缀替代 HTML 元素,通过 initial、animate、exit 定义状态。
  • Variants:定义可复用的动画状态(如 hidden、visible),支持 staggerChildren、delayChildren 编排子元素。
  • 手势:内置 whileHover、whileTap、whileFocus、whileDrag 等。
  • 布局动画:使用 layout 属性自动过渡尺寸位置变化,layoutId 实现共享元素过渡。
  • AnimatePresence:处理组件挂载/卸载时的进出场动画,支持 mode="wait"。
  • 过渡类型:tween(duration、ease 及自定义 cubic-bezier)、spring(stiffness、damping、mass、velocity)、inertia(拖拽用)。
  • 动画属性:transform 类(x、y、z、rotate、rotateX/Y、scale、scaleX/Y、skew、originX/Y)与样式类(opacity、backgroundColor、color、borderRadius、boxShadow、width、height)。
  • 常用模式:交错子元素、useAnimation 编排序列、useScroll + useTransform 滚动联动、drag 配合 dragConstraints / dragElastic / dragMomentum。
  • 无障碍:useReducedMotion 支持减少动效偏好。

使用方式:安装命令为 npm install framer-motion(或 yarn add framer-motion;或 pnpm add framer-motion)。导入 motion 与 AnimatePresence 后按上述模式编写组件。可通过 mcp__plugin_context7_context7__query-docs 并指定 framer-motion 获取最新 API。

适用场景:需要声明式 React 动画、手势驱动交互、布局变化过渡或进出场动画的前端项目;涉及 .tsx/.jsx 中含 framer-motion 导入、animations 目录下的 variants/transitions、或 useAnimation 组件的文件模式。

限制:资料未提供价格、平台兼容范围、性能基准与具体版本要求,暂未提供。安装前请确认项目依赖与版本匹配。