
1. 什么是 <motion.div />?
在 Framer Motion 中,<motion.div /> 不是一个普通的 HTML <div> 元素。它是一个由 Framer Motion 提供的特殊组件,用于增强标准的 HTML 元素,使其具备动画和手势交互的能力。你可以将它看作是 <div> 元素的一个“动画增强版”。
2. 安装 Framer Motion
首先,确保你的 React 项目已经安装了 Framer Motion。如果还没有,可以通过 npm 或 yarn 进行安装:
npm install framer-motion
# 或者
yarn add framer-motion
# 或者
pnpm add framer-motion
3. 导入 motion 组件
在你的 React 组件文件中,你需要从 framer-motion 库中导入 motion 对象:
import {
motion } from
订阅 FreeMac
每周精选:Mac 高效技巧、免费替代付费软件、开发者工具推荐。用对你的 MacBook,省钱 + 提效。