Communitygithub.com

Web动画大师

专业的Web动画开发知识,涵盖CSS动画与过渡、GSAP、Framer Motion、滚动触发动画、性能优化、动画编排、缓动函数、减少动效无障碍以及动画设计模式。

Web动画大师 是什么?

这是一个面向开发者和AI代理的全面Web动画开发技能。该技能提供了一套完整的动画决策框架,帮助开发者在不同场景下选择合适的动画技术,包括简单的CSS过渡、复杂的GSAP时间线、React专用的Framer Motion以及滚动触发的动画。它涵盖了从基础动画实现到高级性能优化的所有方面,强调使用GPU合成属性(transform和opacity)而非昂贵布局属性,并提供了详细的性能调试方法。技能特别关注动画可访问性,包括对`prefers-reduced-motion`的支持和WCAG合规性检查。它还包含了一个常见的反模式列表和一个实用的动画检查清单。该技能适用于所有主流Web动画平台(CSS、GSAP、Framer Motion、ScrollTrigger),并提供了大量可直接使用的代码示例和最佳实践。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/FerroxLabs/murage/tree/HEAD/skills-library/web-animation-master

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Web动画大师 是做什么的?

你是一位专业的Web动画开发者,致力于创建高性能、可访问且视觉上精致的动画。好的动画是隐形的——它引导用户的注意力、传达状态变化、让界面感觉响应迅速。糟糕的动画则是分散注意力、卡顿且令人眩晕的。区别在于理解性能限制、时序和控制力。

动画决策框架

何时使用动画

目的使用动画?示例
状态变化反馈是按钮按下、切换开关、表单提交
空间连续性是页面过渡、展开面板、模态框打开/关闭
吸引注意力适度新通知徽章、重要的行动号召
加载指示是骨架屏、进度条、加载动画
愉悦感/品牌适度Logo动画、引导流程
纯装饰否多余的背景动画、过度使用视差

技术选型

你在构建什么?

├── 简单的悬停/焦点/状态效果
│   └── CSS过渡(无需JS)
│
├── 循环/关键帧动画
│   └── CSS @keyframes(无需JS)
│
├── React组件动画
│   ├── 布局动画、手势、退出动画
│   │   └── Framer Motion(React专用,声明式)
│   └── 复杂时间线、滚动驱动、FLIP
│       └── GSAP(框架无关,最强大)
│
├── 滚动触发动画
│   ├── 简单的滚动展示
│   │   └── CSS滚动驱动动画(现代浏览器)
│   └── 复杂的滚动链接时间线
│       └── GSAP ScrollTrigger
│
└── SVG / Canvas / WebGL动画
    ├── SVG路径绘制、变形
    │   └── GSAP + MotionPathPlugin
    └── 3D、粒子、着色器
        └── Three.js / PixiJS / 直接使用WebGL

CSS动画

过渡(状态A到状态B)

/* 规则:仅动画化性能开销低的属性 */
.button {
  /* 性能友好:transform, opacity(GPU合成,无布局/绘制) */
  transform: scale(1);
  opacity: 1;
  transition: transform 200ms ease-out, opacity 200ms ease-out;
}

.button:hover {
  transform: scale(1.05);
}

.button:active {
  transform: scale(0.97);
}

/* 反模式:动画化布局属性 */
.card-bad {
  width: 200px;
  /* 这会在每一帧触发布局重计算 = 卡顿 */
  transition: width 300ms ease;
}
.card-bad:hover {
  width: 250px;  /* 避免:导致布局抖动 */
}

/* 更好:使用 transform: scale() 替代 */
.card-good {
  transition: transform 300ms ease;
}
.card-good:hover {
  transform: scaleX(1.25);  /* GPU合成,流畅 */
}

关键帧动画

/* 骨架屏加载脉冲 */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.skeleton {
  background: #e0e0e0;
  animation: pulse 1.5s ease-in-out infinite;
}

/* 从右侧滑入 */
@keyframes slide-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.notification {
  animation: slide-in 300ms ease-out forwards;
}

/* 交错列表项(使用自定义属性) */
.list-item {
  animation: fade-up 400ms ease-out backwards;
  animation-delay: calc(var(--index) * 60ms);
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
}
<ul>
  <li class="list-item" style="--index: 0">项目 1</li>
  <li class="list-item" style="--index: 1">项目 2</li>
  <li class="list-item" style="--index: 2">项目 3</li>
</ul>

缓动函数

常用缓动及其应用场景

缓动CSS值用途
ease-outcubic-bezier(0, 0, 0.2, 1)入场(元素出现)
ease-incubic-bezier(0.4, 0, 1, 1)退场(元素消失)
ease-in-outcubic-bezier(0.4, 0, 0.2, 1)位置移动
linearlinear透明度变化、颜色变化、进度条
spring自定义或GSAP交互/物理感觉动画
bounce自定义关键帧趣味性UI、通知

自定义缓动参考

--ease-standard: cubic-bezier(0.2, 0, 0, 1);          /* 通用 */
--ease-decelerate: cubic-bezier(0, 0, 0, 1);           /* 进入元素 */
--ease-accelerate: cubic-bezier(0.3, 0, 1, 1);         /* 离开元素 */
--ease-overshoot: cubic-bezier(0.34, 1.56, 0.64, 1);   /* 趣味弹跳 */

GSAP (GreenSock动画平台)

基本GSAP用法

import gsap from 'gsap';

// 动画化到目标值
gsap.to('.box', {
  x: 200,
  y: 100,
  rotation: 360,
  scale: 1.5,
  opacity: 0.8,
  duration: 1,
  ease: 'power2.out',
});

// 从某值动画化到当前状态
gsap.from('.hero-title', {
  y: 60,
  opacity: 0,
  duration: 0.8,
  ease: 'power3.out',
});

// 交错多个元素
gsap.from('.card', {
  y: 40,
  opacity: 0,
  duration: 0.6,
  stagger: 0.1,         // 每个卡片之间间隔100ms
  ease: 'power2.out',
});

GSAP时间线(编排)

const tl = gsap.timeline({
  defaults: { duration: 0.5, ease: 'power2.out' },
});

tl.from('.hero-bg', { scale: 1.1, opacity: 0, duration: 1 })
  .from('.hero-title', { y: 40, opacity: 0 }, '-=0.3')      // 在前一个动画结束前0.3秒开始
  .from('.hero-subtitle', { y: 30, opacity: 0 }, '-=0.2')
  .from('.hero-cta', { scale: 0.8, opacity: 0 }, '-=0.1')
  .from('.hero-image', { x: 60, opacity: 0, duration: 0.8 }, '-=0.4');

// 控制时间线
tl.play();
tl.pause();
tl.reverse();
tl.seek(0.5);   // 跳转到0.5秒
tl.timeScale(2); // 2倍速度

GSAP ScrollTrigger

import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger);

// 简单:当元素进入视口时触发动画
gsap.from('.feature-card', {
  scrollTrigger: {
    trigger: '.feature-card',
    start: 'top 80%',        // 当元素顶部到达视口80%位置
    end: 'bottom 20%',
    toggleActions: 'play none none reverse',
    // onEnter  onLeave  onEnterBack  onLeaveBack
  },
  y: 60,
  opacity: 0,
  duration: 0.8,
  stagger: 0.15,
});

// 固定区域,滚动擦除效果(滚动关联)
gsap.to('.horizontal-section', {
  scrollTrigger: {
    trigger: '.horizontal-wrapper',
    pin: true,                // 滚动时固定包装器
    scrub: 1,                 // 平滑,滞后滚动1秒
    start: 'top top',
    end: '+=3000',            // 滚动3000px完成动画
  },
  x: '-300%',                 // 向左滑动4个面板
  ease: 'none',
});

Framer Motion (React)

基本动画

import { motion } from 'framer-motion';

// 挂载时动画
function FadeIn({ children }) {
  return (
    <motion.div
      initial={{ opacity: 0, y: 20 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: 0.4, ease: 'easeOut' }}
    >
      {children}
    </motion.div>
  );
}

// 悬停和点击时动画
function AnimatedButton() {
  return (
    <motion.button
      whileHover={{ scale: 1.05 }}
      whileTap={{ scale: 0.95 }}
      transition={{ type: 'spring', stiffness: 400, damping: 17 }}
    >
      点击我
    </motion.button>
  );
}

布局动画 (FLIP)

import { motion, AnimatePresence } from 'framer-motion';

function TodoList({ items, onRemove }) {
  return (
    <ul>
      <AnimatePresence>
        {items.map((item) => (
          <motion.li
            key={item.id}
            layout                           // 自动动画化位置变化
            initial={{ opacity: 0, x: -20 }}
            animate={{ opacity: 1, x: 0 }}
            exit={{ opacity: 0, x: 20, height: 0 }}  // 移除时动画
            transition={{
              layout: { type: 'spring', stiffness: 300, damping: 30 },
              opacity: { duration: 0.2 },
            }}
          >
            {item.text}
            <button onClick={() => onRemove(item.id)}>移除</button>
          </motion.li>
        ))}
      </AnimatePresence>
    </ul>
  );
}

变体(编排子元素)

const container = {
  hidden: { opacity: 0 },
  show: {
    opacity: 1,
    transition: {
      staggerChildren: 0.08,
      delayChildren: 0.2,
    },
  },
};

const item = {
  hidden: { opacity: 0, y: 20 },
  show: { opacity: 1, y: 0 },
};

function StaggeredList({ items }) {
  return (
    <motion.ul variants={container} initial="hidden" animate="show">
      {items.map((i) => (
        <motion.li key={i.id} variants={item}>
          {i.text}
        </motion.li>
      ))}
    </motion.ul>
  );
}

性能优化

合成检查清单

性能友好(GPU合成,无布局或绘制):
  ✓ transform (translate, scale, rotate)
  ✓ opacity
  ✓ filter (blur, brightness, etc.)
  ✓ clip-path (大多数浏览器)

性能昂贵(触发布局或绘制):
  ✗ width, height, top, left, right, bottom
  ✗ margin, padding
  ✗ border-width, border-radius
  ✗ font-size
  ✗ box-shadow (触发绘制)

技巧:用transform替代昂贵属性
  width变化    -> transform: scaleX()
  height变化   -> transform: scaleY()
  top/left变化 -> transform: translate()
  visibility   -> opacity: 0/1

调试性能

// Chrome DevTools:Performance面板
// 1. 在动画播放时录制
// 2. 查找长帧(60fps下超过16.6ms)
// 3. 检查"Rendering"标签:启用"Paint flashing"查看重绘

// 强制GPU合成(谨慎使用)
.animated-element {
  will-change: transform, opacity;  /* 提示浏览器:提升到独立层 */
  /* 动画完成后移除 will-change 以释放GPU内存 */
}

// 在代码中测量帧率
let frames = 0;
let lastTime = performance.now();
function countFrames() {
  frames++;
  const now = performance.now();
  if (now - lastTime >= 1000) {
    console.log(`FPS: ${frames}`);
    frames = 0;
    lastTime = now;
  }
  requestAnimationFrame(countFrames);
}
countFrames();

屏幕外元素的内容可见性

/* 在需要之前不要渲染屏幕外区域 */
.section {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

可访问性

尊重减少动效偏好

/* 始终提供减少动效的替代方案 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 或者只选择性禁用非必要动画 */
@media (prefers-reduced-motion: reduce) {
  .decorative-animation { animation: none; }
  .page-transition { transition: opacity 0.1ms; } /* 即时但触发事件 */
  /* 保留功能动画,如加载旋转器 */
}
// GSAP:检查用户偏好
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

if (prefersReducedMotion) {
  gsap.globalTimeline.timeScale(20); // 近乎即时动画
}

// Framer Motion:内置支持
import { useReducedMotion } from 'framer-motion';

function Component() {
  const shouldReduceMotion = useReducedMotion();
  return (
    <motion.div
      animate={{ x: 100 }}
      transition={shouldReduceMotion ? { duration: 0 } : { duration: 0.5 }}
    />
  );
}

动画可访问性规则

  1. 永远不要仅通过运动来传达信息(部分用户看不到)
  2. 为持续时间超过5秒的动画提供暂停/停止控件
  3. 避免每秒闪烁超过3次(癫痫风险,WCAG 2.3.1)
  4. 不要仅用动画传递含义(例如,抖动的表单字段也应显示错误消息)

常见反模式

  1. 动画化布局属性:width、height、top、left会导致布局抖动。改用transform。

  2. 过多的will-change层:每个will-change元素都会获得自己的GPU层。过多的层会消耗内存,反而降低性能。

  3. 为动画而动画:如果移除动画不影响可用性,那么它可能就不应该存在。每个动画都应有其目的。

  4. 忽略减少动效偏好:15-20%的用户患有前庭障碍或对运动敏感。始终提供prefers-reduced-motion替代方案。

  5. 同步JavaScript动画:使用setInterval或setTimeout制作动画。应使用requestAnimationFrame、CSS动画或内部使用rAF的动画库。

动画检查清单

  • 动画目的已定义(反馈、连续性、注意力、加载)
  • 所选技术复杂度适当
  • 仅动画化可组合属性(transform, opacity)
  • 缓动函数与动画意图匹配(入场用ease-out,退场用ease-in)
  • 实现了prefers-reduced-motion媒体查询
  • 持续时间适当(微交互100-300ms,过渡300-500ms)
  • 内容每秒闪烁不超过3次
  • 在DevTools中测试性能(持续60fps)
  • 动画不阻塞用户交互
  • 加载状态使用骨架屏或微妙的动画,而非到处使用加载旋转器

使用时机

使用此技能当:

  • 设计或实现Web动画大师解决方案
  • 审查或改进现有的Web动画大师方法
  • 对Web动画大师做出架构或实现决策
  • 学习Web动画大师模式和最佳实践
  • 排查Web动画大师相关问题

不要使用此技能当:

  • 问题涉及根本不同的技术领域
  • 一个更具体的兄弟技能涵盖了你所需的精确主题
  • 用户需要完整的动手教程

…

[为翻译截断]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

FerroxLabs/murage

Web animation expertise covering CSS animations and transitions, Web Animations API, Framer Motion, GSAP, scroll-driven animations, layout animations, spring physics, reduce-motion preferences, and performance budgets. Use when the user asks about animation designer, animation designer best practices, or needs guidance on animation designer implementation. Do NOT use when the user needs a different specialized skill or is asking about an unrelated technology domain.

FerroxLabs/murage

Writes board-level narrative updates that complement financial reports with strategic context, competitive positioning, key risks, and forward-looking guidance for board of directors audiences. Use when the user needs to write a board update, board meeting narrative, or director-level briefing. Do NOT use for stakeholder updates to management (use `stakeholder-update`), investor emails (use `investor-update-email`), or full business reports (use `business-report`).

FerroxLabs/murage

>- End-to-end workflow for building a professional photography portfolio from niche selection through shooting, editing, website creation, and client acquisition. Covers gear decisions, shooting technique, post-processing workflow, portfolio curation, online presence, and the transition from hobbyist to working photographer. Use when the user wants to build photography portfolio or needs a structured multi-step process for this goal. Do NOT use when the request is a single-step task or requires professional advice beyond educational guidance.

FerroxLabs/murage

>- End-to-end workflow for creating a high-converting SaaS landing page from copywriting through design, development, SEO optimization, and analytics setup. Covers persuasion frameworks, responsive design, performance optimization, and conversion tracking to turn visitors into customers. Use when the user wants to build saas landing page or needs a structured multi-step process for this goal. Do NOT use when the request is a single-step task or requires professional advice beyond educational guidance.

FerroxLabs/murage

Calculates startup burn rate (gross and net), projects cash runway in months, and builds scenario analysis for different spending and revenue trajectories. Use when the user asks about burn rate, cash runway, how long their money will last, or startup cash management. Do NOT use for personal savings calculations (use budget-planning), full financial modeling (use financial-model-structure), or fundraising narrative (use fundraising-narrative).

FerroxLabs/murage

The user is asking \"how long do we have,\" \"can we afford this hire,\" or \"are we running out.\" Load whenever cash, burn, or time-to-zero shows up — or when a spending decision is on the table and the user doesn't know how many months it costs.

FerroxLabs/murage

Professional corporate video production guidance covering training videos, promotional content, testimonials, and product demos. Includes client brief templates, script approval workflows, achieving professional quality on budget, brand compliance, stakeholder management, and delivery specifications. Use when the user asks about corporate video or needs help with related topics. Do NOT use for unrelated domains or when a more specialized skill exists.

FerroxLabs/murage

Helps artists, designers, and creative professionals curate, organize, and present their work through compelling portfolios across digital platforms, personal websites, and print formats for career advancement. Use when the user asks about creative portfolio builder, related techniques, best practices, or needs guidance in this domain. Do NOT use when the request is outside the scope of creative portfolio builder or requires a different specialized skill.

FerroxLabs/murage

Cross-discipline creative portfolio assessment evaluating artistic cohesion, technical skill, presentation quality, and market positioning. Produces a scored evaluation with recommendations for strengthening creative identity and professional opportunity. Use when the user asks about creative portfolio evaluator, related techniques, best practices, or needs guidance in this domain. Do NOT use when the request is outside the scope of creative portfolio evaluator or requires a different specialized skill.

FerroxLabs/murage

Professional design portfolio evaluation assessing design process, craft quality, range of work, presentation, and industry alignment. Produces a scored review with recommendations for strengthening design practice and career positioning. Use when the user asks about design portfolio reviewer, related techniques, best practices, or needs guidance in this domain. Do NOT use when the request is outside the scope of design portfolio reviewer or requires a different specialized skill.

FerroxLabs/murage

Teaches specific named emotional regulation techniques (the STOP technique, urge surfing, cognitive reframing, emotional labeling, opposite action, and physiological soothing) with step-by-step sequences. Gathers the user's emotional challenges and triggers, then produces a personalized regulation toolkit with technique instructions and a situation-response plan. Use when the user asks about managing emotions, controlling anger, handling frustration, emotional regulation strategies, or building emotional resilience. Do NOT use for clinical emotional dysregulation treatment, personality disorder management, or replacing professional mental health support.

FerroxLabs/murage

Structures a fundraising narrative for startup investors covering traction, market size, business model, use of funds, and milestone targets using standard VC pitch structure. Use when the user asks about fundraising pitch, investor narrative, raising capital, pitch deck story, or investment memo. Do NOT use for sales pitch decks (use sales-pitch-deck), personal loan applications, grant proposals (use grant-proposal-writing), or financial model creation (use financial-model-structure).

FerroxLabs/murage

Interactive storytelling for games covering branching narratives, dialogue trees, environmental storytelling, lore design, character writing for games, quest design, player agency, world-building for interactive media, and narrative integration with game mechanics. Use when the user asks about game narrative writer or needs help with related topics. Do NOT use for unrelated domains or when a more specialized skill exists.

FerroxLabs/murage

Writes Instagram captions with a hook line, story body, hashtag strategy, and platform-optimized call-to-action. Use when the user wants to write an Instagram caption, create Instagram content, or draft text to accompany an Instagram post or reel. Do NOT use for LinkedIn posts (use `linkedin-post`), Twitter threads (use `twitter-thread`), or blog posts (use `blog-post-writing`).

FerroxLabs/murage

Produces conversion-optimized landing page copy with hero section, problem statement, solution, social proof, and CTA sections using conversion copywriting methodology. Use when the user asks to write landing page copy, create a product page, write a sales page, draft conversion copy, or write landing page text for a website. Also useful when asked to write website copy or create a page that converts visitors. Do NOT use for ad copy (use paid-ad-copy), product descriptions for e-commerce listings (use product-description), or full website content strategy (use seo-content-strategy).

FerroxLabs/murage

Guides the user through launching a professional art or creative portfolio from curation through outreach, chaining 5 atomic skills across career-development, design-creative, and writing categories. Covers physical vs. digital portfolio, platform selection, fine art vs. commercial positioning, and curated vs. comprehensive approaches. Use when the user wants to create and launch a portfolio to attract clients, galleries, or employers. Do NOT use for building a job search portfolio in non-creative fields (use land-new-job workflow), personal brand content strategy (use build-personal-brand workflow), or creating the artwork itself.

FerroxLabs/murage

>- Complete YouTube channel launch workflow from niche selection and channel strategy through video production, editing, monetization setup, community building, and personal brand development for sustainable channel growth. Use when the user wants to launch youtube channel or needs a structured multi-step process for this goal. Do NOT use when the request is a single-step task or requires professional advice beyond educational guidance.

FerroxLabs/murage

Run a section-by-section conversion teardown of one landing page — hero, value proposition, social proof, features, objection handling, CTA and footer — plus form, mobile and page-speed audits, ending in prioritised fixes split into quick wins, strategic and long-term, with A/B test hypotheses. Use when one page has traffic and is not converting. Do NOT use for a whole-site marketing audit (use market-audit), for the copy voice and awareness-stage decisions behind it (use copy-awareness-stages) or for the visual system it should sit inside (use mira-visual-system).

FerroxLabs/murage

Comprehensive motion graphics guidance covering title design, lower thirds, animated explainers, kinetic typography, logo animation, After Effects and Apple Motion workflows, design principles for motion, storyboarding for motion, and building a motion design practice. Use when the user asks about motion graphics or needs help with related topics. Do NOT use for unrelated domains or when a more specialized skill exists.

FerroxLabs/murage

Comprehensive animation guidance covering the 12 principles of animation, 2D and 3D production pipelines, tools (Blender, After Effects, Procreate, Toon Boom), frame rates, rigging, motion graphics vs character animation, and building an animation practice from concept to final render. Use when the user asks about animation creator or needs help with related topics. Do NOT use for unrelated domains or when a more specialized skill exists.

相关技能