SuperAPI AI 工具集

animations-transitions

前端与建站

查看项目

更新于 10-16 03:35

技能介绍

用途:这是一个围绕 MUI(Material UI)动画与过渡的参考技能,帮助在 React 应用中为组件添加进出场动画、列表增删动画和基于主题的统一动效。

主要能力:

  1. 内置过渡组件:Fade(透明度)、Grow(缩放+透明度,可设 transformOrigin)、Slide(方向滑动,direction 为 up/down/left/right,可指定 container 相对容器滑动)、Collapse(高度或宽度展开收起,支持 collapsedSize、orientation、timeout='auto')、Zoom(从中心缩放)。常用 props 包括 in、timeout、appear、unmountOnExit、mountOnEnter。
  2. 使用模式:过渡组件向子元素传递 ref,自定义组件须用 forwardRef 转发,否则动画不生效并触发 React 警告;可在可见性切换(保留 DOM)与条件渲染(unmountOnExit/mountOnEnter)之间按需选择。
  3. TransitionGroup:来自 react-transition-group,与 MUI 过渡组件配合实现列表项的添加/移除动画,每个子项需唯一 key,过渡组件作为直接子元素包裹内容。
  4. 自定义过渡:基于 react-transition-group 的 Transition 与 TransitionStatus 状态映射,配合 MUI 的 Box 和 sx 构建可复用过渡;也可封装 MUI 过渡组件(如预置方向、Fade+Slide 组合)。
  5. 主题过渡:theme.transitions.create() 生成 CSS transition 字符串,提供 duration 常量(shortest/shorter/short/standard/complex/enteringScreen/leavingScreen)与 easing 常量(easeInOut/easeOut/easeIn/sharp),可在 createTheme 中自定义。
  6. sx 关键帧:使用 @mui/system 的 keyframes 定义动画(如 pulse、spin、shimmer),结合 animation、animationDelay 实现交错入场等效果。
  7. Framer Motion 集成:需先 npm install framer-motion,可用 AnimatePresence 与 motion.create 包装 MUI 组件(如 Dialog 的 PaperProps)实现更复杂动画。

限制:资料未说明收费、价格或平台支持范围;示例依赖 MUI 与 react-transition-group(Framer Motion 部分需另行安装)。