用途:为 React 与 Next.js 项目编写正确、高性能、无障碍的动画,基于 Motion 库(原 Framer Motion,v12+)。
主要能力:涵盖 motion.* 组件、MotionValue 无重渲染动画、过渡(spring/tween/自定义贝塞尔)、滚动触发淡入(whileInView)、变体交错子元素、AnimatePresence 退出动画、滚动联动动画、useSpring 平滑、useAnimationFrame 连续动画、layout 与 layoutId 布局动画、手势与拖拽动画,以及 useReducedMotion 无障碍处理。
使用方式:导入路径需注意——客户端组件用 import { motion, AnimatePresence } from "motion/react";Next.js 服务端组件用 import * as motion from "motion/react-client";旧包仍可用 import { motion } from "framer-motion"。若项目已依赖 framer-motion,应保持该导入来源,不要混用。motion.* 是客户端组件,App Router 中需 "use client" 或包在客户端组件内。
适用场景:营销页滚动入场、列表交错、模态退出、滚动进度条、动画计数器、页面过渡、渐变文字微光、缩略图到全屏的共享布局动画等。
限制与规则:不要用 useState 做逐帧更新,改用 useMotionValue;不要手动 IntersectionObserver,用 whileInView;不要用 setTimeout 做交错,用 variants 的 staggerChildren;AnimatePresence 子元素必须有唯一 key;不要动画 width/height/top/left,改用 x、y、scale、rotate;避免动画 box-shadow;layout 动画开销大需谨慎使用;必须检查 useReducedMotion()。具体版本兼容与安装命令资料未提供。