animation-motion-design

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Animation & Motion Design

动画与动效设计

Patterns for building performant, accessible animations using Motion (formerly Framer Motion, 18M+ weekly npm downloads) and the View Transitions API (cross-browser support in 2026). Covers layout animations, gesture interactions, exit transitions, micro-interactions, and motion accessibility.
本指南介绍如何使用Motion(原Framer Motion,每周npm下载量超1800万次)和View Transitions API(2026年将实现跨浏览器支持)构建高性能、无障碍的动画。内容涵盖布局动画、手势交互、退出过渡、微交互以及动效无障碍性相关内容。

Quick Reference

速查参考

RuleFileImpactWhen to Use
Layout Animations
rules/motion-layout.md
HIGHShared layout transitions, FLIP animations, layoutId
Gesture Interactions
rules/motion-gestures.md
HIGHDrag, hover, tap with spring physics
Exit Animations
rules/motion-exit.md
HIGHAnimatePresence, unmount transitions
View Transitions API
rules/view-transitions-api.md
HIGHPage navigation, cross-document transitions
Motion Accessibility
rules/motion-accessibility.md
CRITICALprefers-reduced-motion, cognitive load
Motion Performance
rules/motion-performance.md
HIGH60fps, GPU compositing, layout thrash
Total: 6 rules across 3 categories
规则文件影响等级适用场景
布局动画
rules/motion-layout.md
共享布局过渡、FLIP动画、layoutId
手势交互
rules/motion-gestures.md
拖拽、悬停、点击(带弹簧物理效果)
退出动画
rules/motion-exit.md
AnimatePresence、卸载过渡
View Transitions API
rules/view-transitions-api.md
页面导航、跨文档过渡
动效无障碍性
rules/motion-accessibility.md
关键prefers-reduced-motion、认知负荷
动效性能
rules/motion-performance.md
60fps、GPU合成、布局抖动
总计:3大分类下的6条规则

Decision Table — Motion vs View Transitions API

决策表 — Motion vs View Transitions API

ScenarioRecommendationWhy
Component mount/unmountMotionAnimatePresence handles lifecycle
Page navigation transitionsView Transitions APIBuilt-in browser support, works with any router
Complex interruptible animationsMotionSpring physics, gesture interruption
Simple crossfade between pagesView Transitions APIZero JS bundle cost
Drag/reorder interactionsMotiondrag prop with layout animations
Shared element across routesView Transitions APIviewTransitionName CSS property
Scroll-triggered animationsMotionuseInView, useScroll hooks
Multi-step orchestrated sequencesMotionstaggerChildren, variants
场景推荐方案原因
组件挂载/卸载MotionAnimatePresence可处理生命周期
页面导航过渡View Transitions API浏览器原生支持,兼容任意路由
复杂可中断动画Motion弹簧物理效果、手势中断
页面间简单淡入淡出View Transitions API零JS包体积成本
拖拽/重排交互Motion带布局动画的drag属性
跨路由共享元素View Transitions APIviewTransitionName CSS属性
滚动触发动画MotionuseInView、useScroll钩子
多步骤编排序列MotionstaggerChildren、variants

Quick Start

快速开始

Motion — Component Animation

Motion — 组件动画

tsx
import { motion, AnimatePresence } from "motion/react"

const fadeInUp = {
  initial: { opacity: 0, y: 20 },
  animate: { opacity: 1, y: 0 },
  exit: { opacity: 0, y: -10 },
  transition: { type: "spring", stiffness: 300, damping: 24 },
}

function Card({ item }: { item: Item }) {
  return (
    <motion.div {...fadeInUp} layout layoutId={item.id}>
      {item.content}
    </motion.div>
  )
}

function CardList({ items }: { items: Item[] }) {
  return (
    <AnimatePresence mode="wait">
      {items.map((item) => (
        <Card key={item.id} item={item} />
      ))}
    </AnimatePresence>
  )
}
tsx
import { motion, AnimatePresence } from "motion/react"

const fadeInUp = {
  initial: { opacity: 0, y: 20 },
  animate: { opacity: 1, y: 0 },
  exit: { opacity: 0, y: -10 },
  transition: { type: "spring", stiffness: 300, damping: 24 },
}

function Card({ item }: { item: Item }) {
  return (
    <motion.div {...fadeInUp} layout layoutId={item.id}>
      {item.content}
    </motion.div>
  )
}

function CardList({ items }: { items: Item[] }) {
  return (
    <AnimatePresence mode="wait">
      {items.map((item) => (
        <Card key={item.id} item={item} />
      ))}
    </AnimatePresence>
  )
}

View Transitions API — Page Navigation

View Transitions API — 页面导航

tsx
// React Router v7+ with View Transitions
import { Link, useNavigate } from "react-router"

function NavLink({ to, children }: { to: string; children: React.ReactNode }) {
  return <Link to={to} viewTransition>{children}</Link>
}

// CSS for the transition
// ::view-transition-old(root) { animation: fade-out 200ms ease; }
// ::view-transition-new(root) { animation: fade-in 200ms ease; }
tsx
// React Router v7+ 结合View Transitions
import { Link, useNavigate } from "react-router"

function NavLink({ to, children }: { to: string; children: React.ReactNode }) {
  return <Link to={to} viewTransition>{children}</Link>
}

// 过渡效果对应的CSS
// ::view-transition-old(root) { animation: fade-out 200ms ease; }
// ::view-transition-new(root) { animation: fade-in 200ms ease; }

Motion — Accessible by Default

Motion — 默认支持无障碍

tsx
import { useReducedMotion } from "motion/react"

function AnimatedComponent() {
  const shouldReduceMotion = useReducedMotion()

  return (
    <motion.div
      animate={{ x: 100 }}
      transition={shouldReduceMotion
        ? { duration: 0 }
        : { type: "spring", stiffness: 300, damping: 24 }
      }
    />
  )
}
tsx
import { useReducedMotion } from "motion/react"

function AnimatedComponent() {
  const shouldReduceMotion = useReducedMotion()

  return (
    <motion.div
      animate={{ x: 100 }}
      transition={shouldReduceMotion
        ? { duration: 0 }
        : { type: "spring", stiffness: 300, damping: 24 }
      }
    />
  )
}

Rule Details

规则详情

Layout Animations (Motion)

布局动画(Motion)

FLIP-based layout animations with the
layout
prop and shared layout transitions via
layoutId
.
Load:
rules/motion-layout.md
基于FLIP的布局动画,使用
layout
属性,通过
layoutId
实现共享布局过渡。
查看详情:
rules/motion-layout.md

Gesture Interactions (Motion)

手势交互(Motion)

Drag, hover, and tap interactions with spring physics and gesture composition.
Load:
rules/motion-gestures.md
带弹簧物理效果和手势组合的拖拽、悬停、点击交互。
查看详情:
rules/motion-gestures.md

Exit Animations (Motion)

退出动画(Motion)

AnimatePresence for animating components as they unmount from the React tree.
Load:
rules/motion-exit.md
使用AnimatePresence为React树中卸载的组件添加动画效果。
查看详情:
rules/motion-exit.md

View Transitions API

View Transitions API

Browser-native page transitions using
document.startViewTransition()
and framework integrations.
Load:
rules/view-transitions-api.md
基于浏览器原生的页面过渡,使用
document.startViewTransition()
及框架集成方案。
查看详情:
rules/view-transitions-api.md

Motion Accessibility

动效无障碍性

Respecting user motion preferences and reducing cognitive load with motion sensitivity patterns.
Load:
rules/motion-accessibility.md
遵循用户动效偏好,通过动效敏感度模式降低认知负荷。
查看详情:
rules/motion-accessibility.md

Motion Performance

动效性能

GPU compositing, avoiding layout thrash, and keeping animations at 60fps.
Load:
rules/motion-performance.md
GPU合成、避免布局抖动、保持动画60fps。
查看详情:
rules/motion-performance.md

Key Principles

核心原则

  1. 60fps or nothing — Only animate
    transform
    and
    opacity
    (composite properties). Never animate
    width
    ,
    height
    ,
    top
    , or
    left
    .
  2. Centralized presets — Define animation variants in a shared file, not inline on every component.
  3. AnimatePresence for exits — React unmounts instantly; wrap with AnimatePresence to animate out.
  4. Spring over duration — Springs feel natural and are interruptible. Use
    stiffness
    /
    damping
    , not
    duration
    .
  5. Respect user preferences — Always check
    prefers-reduced-motion
    and provide instant alternatives.
  1. 要么60fps,要么不做 — 仅对
    transform
    opacity
    (复合属性)做动画。绝不要对
    width
    height
    top
    left
    做动画。
  2. 集中式预设 — 在共享文件中定义动画变体,不要在每个组件中内联定义。
  3. 退出动画用AnimatePresence — React会立即卸载组件;需用AnimatePresence包裹以实现退出动画。
  4. 优先使用弹簧而非时长 — 弹簧效果更自然且可中断。使用
    stiffness
    /
    damping
    ,而非
    duration
  5. 尊重用户偏好 — 始终检查
    prefers-reduced-motion
    ,并提供即时替代方案。

Performance Budget

性能预算

MetricTargetMeasurement
Transition duration< 400msUser perception threshold
Animation propertiestransform, opacity onlyDevTools > Rendering > Paint flashing
JS bundle (Motion)~16KB gzippedImport only what you use
First paint delay0msAnimations must not block render
Frame drops< 5% of framesPerformance API:
PerformanceObserver
指标目标值测量方式
过渡时长< 400ms用户感知阈值
动画属性仅transform、opacity开发者工具 > 渲染 > 绘制闪烁
JS包体积(Motion)~16KB gzip后仅导入所需内容
首次绘制延迟0ms动画不得阻塞渲染
丢帧率< 5%Performance API:
PerformanceObserver

Anti-Patterns (FORBIDDEN)

反模式(禁止使用)

  • Animating layout properties — Never animate
    width
    ,
    height
    ,
    margin
    ,
    padding
    directly. Use
    transform: scale()
    instead.
  • Missing AnimatePresence — Components unmount instantly without it; exit animations are silently lost.
  • Ignoring prefers-reduced-motion — Causes vestibular disorders for ~35% of users with motion sensitivity.
  • Inline transition objects — Creates new objects every render, breaking React memoization.
  • duration-based springs — Motion springs use
    stiffness
    /
    damping
    , not
    duration
    . Mixing causes unexpected behavior.
  • Synchronous startViewTransition — Always await or handle the promise from
    document.startViewTransition()
    .
  • 对布局属性做动画 — 绝不要直接对
    width
    height
    margin
    padding
    做动画。改用
    transform: scale()
  • 缺少AnimatePresence — 没有它的话组件会立即卸载,退出动画会失效。
  • 忽略prefers-reduced-motion — 会导致约35%的动效敏感用户出现前庭障碍。
  • 内联过渡对象 — 每次渲染都会创建新对象,破坏React memoization。
  • 基于时长的弹簧 — Motion弹簧使用
    stiffness
    /
    damping
    ,而非
    duration
    。混用会导致意外行为。
  • 同步调用startViewTransition — 始终要await或处理
    document.startViewTransition()
    返回的Promise。

Detailed Documentation

详细文档

ResourceDescription
references/motion-vs-view-transitions.mdComparison table, browser support, limitations
references/animation-presets-library.mdCopy-paste preset variants for common patterns
references/micro-interactions-catalog.mdButton press, toggle, checkbox, loading, success/error
资源描述
references/motion-vs-view-transitions.md对比表、浏览器支持情况、限制
references/animation-presets-library.md可直接复制使用的通用模式预设变体
references/micro-interactions-catalog.md按钮点击、切换、复选框、加载、成功/错误状态等微交互

Related Skills

相关技能

  • ork:ui-components
    — shadcn/ui component patterns and CVA variants
  • ork:responsive-patterns
    — Responsive layout and container query patterns
  • ork:performance
    — Core Web Vitals and runtime performance optimization
  • ork:accessibility
    — WCAG compliance, ARIA patterns, screen reader support
  • ork:ui-components
    — shadcn/ui组件模式及CVA变体
  • ork:responsive-patterns
    — 响应式布局及容器查询模式
  • ork:performance
    — 核心Web指标及运行时性能优化
  • ork:accessibility
    — WCAG合规、ARIA模式、屏幕阅读器支持