Communitygithub.com

動畫與動態效果技能

CSS 動畫、過渡效果與滾動驅動動畫,並注重無障礙性(prefers-reduced-motion)。適用於添加動態效果、懸停效果、載入狀態或基於滾動的動畫。

動畫與動態效果技能 是什麼?

此技能涵蓋 CSS 動畫與過渡效果的實作,特別強調無障礙性(尊重使用者動態偏好)與效能(避免頁面卡頓與佈局抖動)。它提倡「減少動畫優先」的設計方法,確保預設狀態下沒有動畫,僅在使用者未要求減少動畫時才添加動態效果。技能詳細介紹了如何使用 `prefers-reduced-motion` 媒體查詢來為偏好減少動畫的使用者提供替代方案,並維護了高效能的動畫屬性清單,例如僅使用 `transform` 與 `opacity` 等合成器屬性,避免觸發昂貴的佈局重新計算。此技能支援所有現代瀏覽器,並針對不同平台(Chrome、Firefox、Safari、macOS、Windows、iOS、Android)提供了測試設定方法。此外,它還涵蓋了常見的動畫模式,包括懸浮效果、載入旋轉器、骨架螢幕、進場動畫、檢視轉換 API、滾動驅動動畫以及微互動(如按鈕按下與切換開關),並提供了相關的設計 Token 整合建議。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/David-Li0406/meta-skill-evloving/tree/HEAD/skill-flow/data/skills-refined-36k/skillsmp/animation-motion

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

動畫與動態效果技能 是做什麼的?

本技能涵蓋 CSS 動畫與過渡效果,重點在於無障礙性(尊重使用者動態偏好)與效能(避免頁面卡頓與佈局抖動)。

相關提示: 如需純 CSS 的互動模式(如無 JavaScript 的頁籤、摺疊面板、切換開關),請參閱 progressive-enhancement 技能。

設計原則

動態效果應符合以下原則:

  1. 有目的的 - 引導注意力、顯示關聯性、提供回饋
  2. 尊重的 - 遵守 prefers-reduced-motion 偏好
  3. 高效能的 - 盡可能使用僅合成器屬性
  4. 微妙的 - 增強體驗,而非分散或壓倒使用者

減少動畫優先

始終以減少動畫作為預設狀態,然後再為未選擇退出動畫的使用者添加動態效果。

模式

/* 基礎:無動畫(減少動畫的預設值) */
.element {
  transition: none;
}

/* 僅在使用者未要求減少動畫時添加動態效果 */
@media (prefers-reduced-motion: no-preference) {
  .element {
    transition: transform 0.3s ease, opacity 0.3s ease;
  }
}

為什麼要減少動畫優先?

方法問題
先動畫,再移除使用者會在媒體查詢套用前看到動畫閃現
先減少,再添加安全的預設值,動畫作為漸進增強

尊重使用者偏好

prefers-reduced-motion 媒體查詢

/* 使用者偏好減少動畫 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

細緻的減少動畫

與其移除所有動畫,不如提供替代方案:

/* 為無偏好的使用者提供完整動畫 */
@media (prefers-reduced-motion: no-preference) {
  .card {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }

  .card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
  }
}

/* 為減少動畫的使用者提供微妙的替代方案 */
@media (prefers-reduced-motion: reduce) {
  .card {
    transition: box-shadow 0.15s ease;
  }

  .card:hover {
    box-shadow: var(--shadow-md);
  }
}

JavaScript 偵測

const prefersReducedMotion = window.matchMedia(
  '(prefers-reduced-motion: reduce)'
).matches;

if (prefersReducedMotion) {
  // 使用即時過渡或跳過動畫
  element.style.transition = 'none';
} else {
  // 完整動畫
  element.animate(keyframes, options);
}

高效能屬性

僅合成器屬性(快速)

這些屬性可以在不觸發佈局或繪製的情況下進行動畫處理:

屬性用途
transform移動、縮放、旋轉
opacity淡入/淡出
filter模糊、亮度(GPU 加速)
/* 好:僅合成器 */
.card:hover {
  transform: translateY(-4px) scale(1.02);
  opacity: 0.9;
}

應避免動畫的屬性

這些屬性會觸發昂貴的佈局重新計算:

屬性問題
width, height佈局重新計算
top, left, right, bottom佈局重新計算
margin, padding佈局重新計算
border-width佈局重新計算
font-size佈局 + 文字回流
/* 壞:觸發佈局 */
.card:hover {
  margin-top: -4px;  /* 佈局抖動 */
  height: 110%;      /* 佈局抖動 */
}

/* 好:改用 transform */
.card:hover {
  transform: translateY(-4px) scaleY(1.1);
}

提升到合成器圖層

謹慎使用 will-change 於已知的動畫:

/* 僅用於將會動畫化的元素 */
.animated-element {
  will-change: transform, opacity;
}

/* 動畫完成後移除 */
.animated-element.animation-done {
  will-change: auto;
}

警告: 不要對許多元素套用 will-change——它會消耗記憶體。


過渡模式

設計 Token 整合

:root {
  /* 時間軸 */
  --duration-instant: 0.1s;
  --duration-fast: 0.15s;
  --duration-normal: 0.3s;
  --duration-slow: 0.5s;

  /* 緩動函數 */
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

常見過渡

/* 懸浮升起效果 */
@media (prefers-reduced-motion: no-preference) {
  .card {
    transition:
      transform var(--duration-fast) var(--ease-out),
      box-shadow var(--duration-fast) var(--ease-out);
  }

  .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
}

/* 焦點環 */
@media (prefers-reduced-motion: no-preference) {
  button {
    transition: outline-offset var(--duration-instant) var(--ease-out);
  }

  button:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
  }
}

/* 淡入 */
@media (prefers-reduced-motion: no-preference) {
  .fade-in {
    animation: fadeIn var(--duration-normal) var(--ease-out);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

動畫模式

關鍵幀動畫

/* 微妙的脈衝以吸引注意 */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@media (prefers-reduced-motion: no-preference) {
  .notification-badge {
    animation: pulse 2s var(--ease-in-out) infinite;
  }
}

/* 減少動畫的替代方案:無動畫 */
@media (prefers-reduced-motion: reduce) {
  .notification-badge {
    animation: none;
  }
}

載入旋轉器

/* 尊重減少動畫的旋轉器 */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
}

@media (prefers-reduced-motion: no-preference) {
  .spinner {
    animation: spin 1s linear infinite;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    /* 靜態指示器或脈衝透明度 */
    animation: none;
    border-style: dotted;
  }
}

骨架載入

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-color) 25%,
    var(--background-alt) 50%,
    var(--surface-color) 75%
  );
  background-size: 200% 100%;
}

@media (prefers-reduced-motion: no-preference) {
  .skeleton {
    animation: shimmer 1.5s infinite;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background: var(--background-alt);
  }
}

進場動畫

淡入與滑入

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .animate-in {
    animation: fadeSlideUp var(--duration-normal) var(--ease-out) both;
  }

  /* 子元素錯開 */
  .animate-in > * {
    animation: fadeSlideUp var(--duration-normal) var(--ease-out) both;
  }

  .animate-in > *:nth-child(1) { animation-delay: 0ms; }
  .animate-in > *:nth-child(2) { animation-delay: 50ms; }
  .animate-in > *:nth-child(3) { animation-delay: 100ms; }
  .animate-in > *:nth-child(4) { animation-delay: 150ms; }
}

@media (prefers-reduced-motion: reduce) {
  .animate-in,
  .animate-in > * {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

縮放進入

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: no-preference) {
  dialog[open] {
    animation: scaleIn var(--duration-fast) var(--ease-out);
  }
}

檢視轉換 API

用於頁面轉換(漸進增強):

/* 啟用檢視轉換 */
@view-transition {
  navigation: auto;
}

/* 預設交叉淡入 */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: var(--duration-normal);
}

/* 尊重減少動畫 */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.01ms;
  }
}

/* 特定元素的命名轉換 */
.hero-image {
  view-transition-name: hero;
}

::view-transition-old(hero),
::view-transition-new(hero) {
  animation-duration: var(--duration-slow);
}

滾動驅動動畫

現代 CSS 滾動驅動動畫(漸進增強):

/* 滾動時淡入 */
@keyframes fadeInOnScroll {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: no-preference) {
  .scroll-reveal {
    animation: fadeInOnScroll linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-reveal {
    opacity: 1;
    transform: none;
  }
}

微互動

按鈕按下

@media (prefers-reduced-motion: no-preference) {
  button {
    transition: transform var(--duration-instant) var(--ease-out);
  }

  button:active {
    transform: scale(0.98);
  }
}

切換開關

.toggle-track {
  width: 44px;
  height: 24px;
  background: var(--surface-color);
  border-radius: 12px;
}

.toggle-thumb {
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transform: translateX(2px);
}

@media (prefers-reduced-motion: no-preference) {
  .toggle-thumb {
    transition: transform var(--duration-fast) var(--ease-out);
  }
}

.toggle-input:checked + .toggle-track .toggle-thumb {
  transform: translateX(22px);
}

核取方塊勾選

.checkbox-icon {
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
}

@media (prefers-reduced-motion: no-preference) {
  .checkbox-icon {
    transition: stroke-dashoffset var(--duration-fast) var(--ease-out);
  }
}

.checkbox-input:checked + .checkbox-box .checkbox-icon {
  stroke-dashoffset: 0;
}

動畫時間長度指南

動畫類型時間長度原因
微互動100-150ms即時回饋
簡單過渡150-300ms明顯但快速
複雜動畫300-500ms有時間追蹤
頁面過渡300-500ms情境轉換
載入指示器1000-2000ms顯示一個週期

100ms 規則

使用者認為 100ms 內的回應是即時的。適用於:

  • 按鈕啟動狀態
  • 焦點指示器
  • 切換開關

應避免的危險模式

前庭觸發因素

這些可能導致暈眩或癲癇:

模式問題替代方案
視差滾動前庭問題靜態或微妙的視差
自動播放影片非預期的動態根據互動播放
閃爍(>3Hz)癲癇風險無閃爍
大幅縮放前庭問題淡入過渡
旋轉/轉動方向迷失淡入或滑入
/* 壞:激烈的視差 */
.parallax {
  transform: translateY(calc(var(--scroll) * 0.5));
}

/* 更好:在減少動畫時微調或停用 */
@media (prefers-reduced-motion: reduce) {
  .parallax {
    transform: none;
  }
}

無限動畫

/* 壞:持續運動 */
.attention-seeker {
  animation: bounce 1s infinite;
}

/* 更好:限制疊代次數 */
.attention-seeker {
  animation: bounce 1s 3; /* 僅 3 次 */
}

/* 最佳:根據互動觸發 */
.attention-seeker:hover {
  animation: bounce 0.5s;
}

測試檢查清單

瀏覽器開發者工具

  1. Chrome:Rendering > Emulate CSS media feature > prefers-reduced-motion: reduce
  2. Firefox:about:config > ui.prefersReducedMotion (0=no-preference, 1=reduce)
  3. Safari:Develop > Experimental Features > Reduced Motion

系統設定

  • macOS:System Preferences > Accessibility > Display > Reduce motion
  • iOS:Settings > Accessibility > Motion > Reduce Motion
  • Windows:Settings > Ease of Access > Display > Show animations
  • Android:Settings > Accessibility > Remove animations

檢查清單

添加動畫或過渡時:

  • 是否已尊重 prefers-reduced-motion
  • 減少動畫時是否有有意義的替代方案(不僅是停用)
  • 僅使用合成器屬性進行動畫(transform, opacity)
  • will-change 是否謹慎使用,並在動畫完成後移除
  • 時間長度 Token 是否一致使用
  • 無閃爍內容(每秒閃爍少於 3 次)
  • 無限動畫是否有目的且可停止
  • 視差與大幅運動是否為選用增強
  • 載入狀態是否可在無動畫情況下正常運作
  • 動畫是否增強而非分散注意力

相關技能

  • css-author - 使用原生 @import、@layer 階層的現代 CSS 組織...
  • progressive-enhancement - 以 HTML 為優先的開發,搭配純 CSS 互動模式
  • performance - 撰寫高效能的 HTML 頁面
  • accessibility-checker - 確保 WCAG2AA 無障礙合規性

Individual skills in this repo

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

David-Li0406/meta-skill-evloving

Browser automation with persistent page state. Use when users ask to navigate websites, fill forms, take screenshots, extract web data, test web apps, or automate browser workflows. Trigger phrases include "go to [url]", "click on", "fill out the form", "take a screenshot", "scrape", "automate", "test the website", "log into", or any browser interaction request.

David-Li0406/meta-skill-evloving

Create technical diagrams using Mermaid syntax for architecture, sequences, ERDs, flowcharts, and state machines. Use for visualizing system design, data flows, and processes. Triggers: diagram, mermaid, architecture diagram, sequence diagram, flowchart, ERD, entity relationship, state diagram, C4 model, component diagram, visualize, draw.

David-Li0406/meta-skill-evloving

Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. When Claude needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks

David-Li0406/meta-skill-evloving

Complete color manipulation and green screen effects system. PROACTIVELY activate for: (1) Green screen/chromakey removal, (2) Color grading with LUTs, (3) Color correction (levels, curves, white balance), (4) Colorkey/color removal effects, (5) Hue/saturation manipulation, (6) Color space conversions (BT.709, BT.2020, HDR), (7) Color isolation effects, (8) Teal and orange look, (9) Vintage/film looks, (10) Color keying for transparency. Provides: chromakey and colorkey filters, LUT application (lut3d), curves and levels adjustment, color balance, selective color manipulation, color space handling, HDR tone mapping, professional color grading chains.

David-Li0406/meta-skill-evloving

Convert files and office documents to Markdown. Supports PDF, DOCX, PPTX, XLSX, images (with OCR), audio (with transcription), HTML, CSV, JSON, XML, ZIP, YouTube URLs, EPubs and more.

David-Li0406/meta-skill-evloving

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

David-Li0406/meta-skill-evloving

Build with OpenAI's stateless APIs - Chat Completions (GPT-5, GPT-4o), Embeddings, Images (DALL-E 3), Audio (Whisper + TTS), and Moderation. Includes Node.js SDK and fetch-based approaches for Cloudflare Workers. Use when: implementing chat completions with GPT-5/GPT-4o, streaming responses with SSE, using function calling/tools, creating structured outputs with JSON schemas, generating embeddings for RAG (text-embedding-3-small/large), generating images with DALL-E 3, editing images with GPT-Image-1, transcribing audio with Whisper, synthesizing speech with TTS (11 voices), moderating content (11 safety categories), or troubleshooting rate limits (429), invalid API keys (401), function calling failures, streaming parse errors, embeddings dimension mismatches, or token limit exceeded.

David-Li0406/meta-skill-evloving

Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. When Claude needs to fill in a PDF form or programmatically process, generate, or analyze PDF documents at scale.

David-Li0406/meta-skill-evloving

Presentation creation, editing, and analysis. When Claude needs to work with presentations (.pptx files) for: (1) Creating new presentations, (2) Modifying or editing content, (3) Working with layouts, (4) Adding comments or speaker notes, or any other presentation tasks

David-Li0406/meta-skill-evloving

Comprehensive spreadsheet creation, editing, and analysis with support for formulas, formatting, data analysis, and visualization. When Claude needs to work with spreadsheets (.xlsx, .xlsm, .csv, .tsv, etc) for: (1) Creating new spreadsheets with formulas and formatting, (2) Reading or analyzing data, (3) Modify existing spreadsheets while preserving formulas, (4) Data analysis and visualization in spreadsheets, or (5) Recalculating formulas

David-Li0406/meta-skill-evloving

Download YouTube videos with customizable quality and format options. Use this skill when the user asks to download, save, or grab YouTube videos. Supports various quality settings (best, 1080p, 720p, 480p, 360p), multiple formats (mp4, webm, mkv), and audio-only downloads as MP3.

David-Li0406/meta-skill-evloving

Best practices for Remotion - Video creation in React

David-Li0406/meta-skill-evloving

Provides bidirectional translation (Chinese/English), grammar checking, and sentence polishing. Supports specific tense constraints, context-aware tone adjustment, and natural expression optimization. Outputs direct text without formatting.

David-Li0406/meta-skill-evloving

指导如何通过自定义注解(如@Unicom)标识Dubbo接口,利用BeanDefinitionRegistryPostProcessor在启动时扫描并动态注册ReferenceBean,实现RPC调用的封装。

David-Li0406/meta-skill-evloving

生成Python脚本,利用FFmpeg将图片序列按3x3布局合并,或将合并图拆分。要求使用subprocess模块执行命令,并支持用户交互式输入路径。

David-Li0406/meta-skill-evloving

SOP for extracting and analyzing promotional activity details, handling time formatting, location mapping, payment logic, and step-by-step process validation.

David-Li0406/meta-skill-evloving

Specializes in creating TikTok short video scripts using an anthropomorphic 'Chef' perspective to explain wildlife food chains and survival environments, utilizing real field footage.

David-Li0406/meta-skill-evloving

针对TikTok平台,以拟人化视角(如动物作为厨师)创作系列短视频脚本。重点介绍野生动物、食物链及生态环境,要求使用野外实拍素材,风格幽默且具有教育意义。

David-Li0406/meta-skill-evloving

Generates KWL (Know, Want to know, Learned) charts for educational videos, specifically BrainPOP, using simple 7th-grade language and short, concise bullet points.

David-Li0406/meta-skill-evloving

Tracks complex, multi-session work using the Beads issue tracker and dependency graphs, and provides persistent memory that survives conversation compaction. Use when work spans multiple sessions, has complex dependencies, or needs persistent context across compaction cycles. Trigger with phrases like "create task for", "what's ready to work on", "show task", "track this work", "what's blocking", or "update status".

相關技能