Communitygithub.com

アクセシブルアニメーション(段階的モーション削減)

ユーザーが「prefers-reduced-motionを尊重」「モーションをアクセシブルに」「GSAP/Framer Motion/Lenisを段階的モーション削減に対応」などと依頼した場合に使用します。CSSとJSで、すべてを削除するのではなく段階的にモーションを制御するパターンを提供します。

アクセシブルアニメーション(段階的モーション削減) とは?

このスキルは、ウェブUIにおけるアニメーションのアクセシビリティを向上させるための包括的なガイドを提供します。特に、前庭障害を持つユーザーがトリガーとなる動き(パララックス、大きなスライド、3D回転、自動再生カルーセルなど)に対して、OSの「動きを減らす」設定(`prefers-reduced-motion: reduce`)を尊重しつつ、すべてのアニメーションを無効にするのではなく、3つのティア(Tier 1: 完全削除、Tier 2: ソフト化/短縮、Tier 3: 常に維持)に分類して段階的に対処します。CSSのメディアクエリによるグローバルなセーフティネットと、GSAP、Framer Motion、LenisなどのJavaScriptライブラリ向けの`matchMedia`による動的な制御方法を提供します。また、React用の`useReducedMotion`フックの実装例や、WCAG 2.2.2、2.3.3、C39への対応マッピング、さらに実際の動作確認のためのスクリーンショット検証手順も含まれています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/nehakanjamala/personal_website/tree/HEAD/.agents/skills/accessible-animation

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

アクセシブルアニメーション(段階的モーション削減) は何をしますか?

prefers-reduced-motion: reduce を、単なる「全停止スイッチ」ではなく段階的な劣化として尊重します。OSレベルの設定(macOS: システム設定 > アクセシビリティ > 表示 > 動きを減らす; Windows: 設定 > アクセシビリティ > 視覚効果 > アニメーション効果; iOS/Android でも同様)は、前庭を刺激する動きが吐き気、めまい、頭痛を引き起こす可能性があることを示しています。正しい対応は、危険な動きを取り除きつつ、方向を示す手がかりは維持することです。

使用するタイミング

ウェブUIでアニメーションを追加または監査するとき、ユーザーが乗り物酔いやWCAGの指摘を報告したとき、またはアニメーションライブラリ(GSAP、Framer Motion、Lenisスムーススクロール、Anime.js、CSSキーフレーム)をアクセシブルなプロダクトに統合するときに使用します。

基本原則: モーションを段階的に制御し、全停止しない

すべてのアニメーションを削除することは、よくある過剰対応です。トランジションなしの瞬間的な状態変化は、より混乱を招くことがあり(要素がテレポートする)、有用なアフォーダンス(フォーカスリング、進捗を示すローディングスピナー)を失わせます。すべてのアニメーションを3つのティアに分類します:

  • Tier 1 — 完全に削除(前庭トリガー)。パララックス、ビューポート全体にわたる大きなスライド/移動、大きな要素の拡大縮小/ズーム、3D回転とスピン、自動再生されるカルーセルとマーキー、スムーススクロールの乗っ取り(Lenis/Locomotive)、スクロール連動のピン留めシーン、モーションパスアニメーション、画面の大部分を動かしたり奥行きや自己移動を暗示するもの。
  • Tier 2 — ソフト化 / 短縮。動きを短い不透明度フェード(≤200ms)に置き換えます。距離と時間を短縮します。トランジションの事実は維持(要素がテレポートしないように)しますが、変位は取り除きます。600msの左からのスライドインを150msのクロスフェードに置き換えます。
  • Tier 3 — 常に維持。不透明度フェード、色/背景のトランジション、フォーカスリングのトランジション、ローディングインジケーター、そして意味にとって不可欠な動き(WCAGでは必須アニメーションを許可)。これらは自己移動を暗示しないため、前庭反応を引き起こすことはめったにありません。

CSSレイヤー: メディアクエリによるゲート制御

デフォルトでモーションを記述し、削減クエリの下で上書きします。グローバルなセーフティネットとターゲットを絞った上書きを組み合わせることを推奨します。

/* グローバルセーフティネット: 暴走するモーションを無効化するが、盲目的に0sにしない。
   transitionend/animationendを待つJSを壊す可能性があるため、0.01msを使用。 */
@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;          /* スムーススクロールを無効化 */
  }
}

グローバルネットは最後の手段です。その上に意図的な階層的な上書きをレイヤーして、Tier 3のモーションが生き残るようにします:

.card {
  transition: transform 400ms ease, opacity 400ms ease, background-color 200ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .card {
    /* Tier 2: transform(移動)を削除、opacity + color(Tier 3)は維持 */
    transition: opacity 150ms ease, background-color 150ms ease;
  }
  .parallax-layer { transform: none !important; }        /* Tier 1: 削除 */
  .hero-zoom      { animation: none !important; }        /* Tier 1: 削除 */
}

モーションを有効にするために、(prefers-reduced-motion: no-preference) という肯定的なクエリを使用します。これは、凝ったエフェクトにとって最も安全なパターンです:

.hero { opacity: 1; } /* デフォルトで可視、静的 */
@media (prefers-reduced-motion: no-preference) {
  .hero { animation: zoom-in 1.2s ease both; } /* 許可されている場合のみアニメーション */
}

JSレイヤー: matchMediaによるゲート制御

CSSだけではJS駆動のアニメーション(GSAPタイムライン、Framerの animate、キャンバス/WebGL、Lenis)を制御できません。matchMedia を使用して同じシグナルを読み取り、ライブの変更(ユーザーがOS設定をリロードなしで切り替える)に反応します。

const REDUCE_QUERY = '(prefers-reduced-motion: reduce)';

export function prefersReducedMotion() {
  return typeof window !== 'undefined'
    && window.matchMedia
    && window.matchMedia(REDUCE_QUERY).matches;
}

// ライブ更新: OS設定の切り替えが即座に反映されるようにリスナーを設定。
export function onReducedMotionChange(cb) {
  const mq = window.matchMedia(REDUCE_QUERY);
  const handler = (e) => cb(e.matches);
  mq.addEventListener('change', handler);          // モダンAPI
  return () => mq.removeEventListener('change', handler);
}

ライブラリゲート制御、再利用可能なレイヤーとして適用

// GSAP — matchMedia()を使用: GSAPは変更時に条件付きセットアップを元に戻す。
import gsap from 'gsap';
const mm = gsap.matchMedia();
mm.add({
  motionOK: '(prefers-reduced-motion: no-preference)',
  motionReduce: '(prefers-reduced-motion: reduce)',
}, (ctx) => {
  const { motionOK } = ctx.conditions;
  if (motionOK) {
    gsap.from('.hero', { y: 80, opacity: 0, duration: 1 });   // Tier 1 移動
  } else {
    gsap.from('.hero', { opacity: 0, duration: 0.15 });        // Tier 2 フェード
  }
});

// Lenisスムーススクロール — 削減時はインスタンス化しない。
import Lenis from 'lenis';
let lenis = null;
if (!prefersReducedMotion()) {
  lenis = new Lenis();
  const raf = (t) => { lenis.raf(t); requestAnimationFrame(raf); };
  requestAnimationFrame(raf);
}

React: useReducedMotion フック

import { useState, useEffect } from 'react';

export function useReducedMotion() {
  const query = '(prefers-reduced-motion: reduce)';
  const get = () =>
    typeof window !== 'undefined' && window.matchMedia
      ? window.matchMedia(query).matches
      : false;
  const [reduced, setReduced] = useState(get);

  useEffect(() => {
    const mq = window.matchMedia(query);
    const onChange = () => setReduced(mq.matches);
    onChange();                                   // ハイドレーション後に同期
    mq.addEventListener('change', onChange);
    return () => mq.removeEventListener('change', onChange);
  }, []);

  return reduced;
}
// Framer Motion には独自の useReducedMotion() があります; 上記のフックも使えます。
import { motion } from 'framer-motion';
function Card() {
  const reduced = useReducedMotion();
  return (
    <motion.div
      initial={reduced ? { opacity: 0 } : { opacity: 0, y: 40 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: reduced ? 0.15 : 0.5 }}
    />
  );
}

SSRでレンダリングされる状態は false(モーションあり)に初期化し、useEffect で再同期してハイドレーションの不一致を回避します。OSの値はクライアント側でしかわかりません。

WCAG マッピング

  • 2.3.3 インタラクションによるアニメーション(AAA)。インタラクション(スクロール、ホバー)によってトリガーされるモーションは、必須でない限り無効化可能でなければなりません。prefers-reduced-motion を尊重することが標準的な手法です。
  • C39(CSSテクニック)。prefers-reduced-motion クエリを使用してモーションを防ぎます。これは名前付きの十分なテクニックです。
  • 2.2.2 一時停止、停止、非表示(A)。5秒を超える自動再生モーションは、一時停止/停止の機能を提供しなければなりません。自動カルーセルとマーキーはメディアクエリに関係なくこれに違反します — コントロールも提供してください。

成果物と検証(スタンドアロンHTML)

パッケージ化されたヘルパー(scripts/): scripts/seek-shot.sh anim.html 0 1.5 3 は ?t=N ハーネスをフリーズし、各瞬間のスクリーンショットを撮ります; scripts/contact-sheet.sh sheet.png frame-*.png はそれらを一覧表示して一目で確認できるようにします。詳細は scripts/README.md を参照。

セルフコンテナなデモの場合、成果物はブラウザで直接開く1つのHTMLファイル(マークアップ、CSS、および任意のJS(GSAP/matchMedia をCDNからインライン化)を含み、ビルド手順は不要)です。このスキルでは、検証がポイントです:通常のパスとモーション削減パスの両方のスクリーンショットを撮り、階層化が正しいことを確認する必要があります。

出力コントラクト:

  • 完全なモーションとその階層化されたモーション削減オーバーライド(CSSクエリ + JS駆動モーション用の matchMedia/gsap.matchMedia())を含む1つの .html ファイル。
  • フレームをフリーズするためのシークハーネスと、スクリーンショット用にモーション削減コードパスを強制する方法。

シークハーネス — フレームをフリーズ、プリファレンスを強制。 ?t=N でタイムラインをフリーズ; ?reduce=1 は OS 設定がオフの場合でも削減パスを強制(CSS は JS からトグルできないため、JS をゲート制御するのと同じフラグをクエリし、CSS レイヤー用に OS/ブラウザのプリファレンスをエミュレートしてスクリーンショットを撮る):

<script>
  const q = new URLSearchParams(location.search);
  const reduce = q.get("reduce") === "1"
    || window.matchMedia("(prefers-reduced-motion: reduce)").matches;
  // `reduce` に応じて条件付きでモーションを構築(Tier-1 削除、Tier-2 ソフト化、Tier-3 維持)
  const t = q.get("t");
  if (t !== null) { tl.pause(); tl.seek(parseFloat(t)); }      // GSAP; CSS: el.style.animationDelay=(-t)+"s"; playState="paused"
  window.__ready = true;
</script>

検証ループ — 両方の状態のスクリーンショット: 通常のパスと削減パスの両方を、それぞれアニメーション途中でキャプチャし、Tier-1 のモーションがなくなっていること、Tier-2 が短いフェードになっていること、Tier-3 が維持されていることを確認します。CSSレイヤー用にプリファレンスをエミュレートします(Playwright --reduced-motion=reduce; エージェントのブラウザツールでもエミュレート可能):

npx playwright screenshot --wait-for-timeout=500 "file://$PWD/demo.html?t=0.6" normal.png
npx playwright screenshot --reduced-motion=reduce --wait-for-timeout=500 "file://$PWD/demo.html?t=0.6&reduce=1" reduced.png

終了前の確認事項:

  1. スタンドアロンで開くこと — コンソールエラーがなく、CDN(もしあれば)が読み込まれること。
  2. フリーズ + ?reduce=1(および --reduced-motion=reduce)が両方のコードパスを確実に実行すること。
  3. 両方の状態で、アニメーション途中のスクリーンショットが撮られていること — 通常は意図的、削減後は Tier-1 が削除/Tier-2 がソフト化されていること。
  4. prefers-reduced-motion が「全停止スイッチ」ではなく階層化として尊重されていること — テレポートなし、Tier-3 のフェード/フォーカスリング/スピナーは維持; 5秒を超える自動モーションには一時停止コントロールがあること(2.2.2)。
  5. イージングが両方のパスで意図的であること — 偶然の linear がないこと、時間が適切であること(削減フェード ≤200ms、0.01ms であって 0s ではないこと)。

クイックリファレンス

モーションタイプティア削減時の動作
パララックス / 奥行き1削除(transform: none)
大きなスライド / 移動1削除またはフェードに置き換え
拡大縮小 / ズーム(大)1削除
スピン / 3D回転1削除(animation: none)
自動カルーセル / マーキー1停止 + 一時停止コントロールを提供(2.2.2)
スムーススクロール(Lenis)1インスタンス化しない
小さなスライド / ポップイン2クロスフェード ≤200ms
不透明度フェード3維持(長ければ短縮)
色 / フォーカスリングトランジション3維持
ローディングスピナー3維持(不可欠なフィードバック)

注意点

  • animation-duration: 0s は animationend/transitionend を待つコードを壊す可能性があります; 0.01ms を使用してイベントが確実に発生するようにしてください。
  • グローバルな * リセットだけでは Tier 3 のモーションを過剰に削除します; 常に意図的なオーバーライドをレイヤーしてください。
  • animation-iteration-count: 1 を忘れると、無限スピンがほぼゼロの継続時間で実行され続けます(CPU負荷、アニメーションは継続)。
  • メディアクエリは JS/キャンバス/WebGL をカバーしません — これらは matchMedia でゲート制御するか、ループが停止しません。
  • OS設定の切り替えはページのリロードをトリガーしません; change リスナーがないと、ページは古い状態を維持します。
  • SSR: レンダリング中に matchMedia を読み取るとエラーがスローされるか、ミスマッチが発生します; デフォルトでモーションありにし、エフェクトで同期してください。
  • 自動再生モーションには、モーション削減がオフの場合でも、表示可能な一時停止コントロールが必要です(2.2.2 はレベル A)。

参考ファイル

  • references/patterns.md — GSAP matchMedia の完全なティアダウン、Framer Motion MotionConfig、ライブトグルでのLenisの開始/停止、再利用可能な animateWithMotionPreference ラッパー、一時停止コントロール付きマーキー、およびティア分類監査チェックリスト。

Individual skills in this repo

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

nehakanjamala/personal_website

This skill should be used when the user asks to "fix janky CSS animation", "make animation 60fps", "stop layout thrashing", "animate width/height/top/left smoothly", "convert animation to transform", "animate box-shadow performantly", "animate height auto", "FLIP animation", or "why is my scroll/hover animation choppy".

nehakanjamala/personal_website

Create, modify, debug, and deploy Apify Actors, and write their input and output schemas. Use when building an Actor from scratch, changing or troubleshooting Actor code, generating or updating .actor schema files, or pushing an Actor to the Apify platform. To wrap an existing non-Actor project, use apify-actorization instead.

nehakanjamala/personal_website

Convert existing projects into Apify Actors - serverless cloud programs. Actorize JavaScript/TypeScript (SDK with Actor.init/exit), Python (async context manager), or any language (CLI wrapper). Use when migrating code to Apify, wrapping CLI tools as Actors, or adding Actor SDK to existing projects.

nehakanjamala/personal_website

Deprecated. Output schema generation moved to the apify-actor-development skill; prefer that skill whenever it is available.

nehakanjamala/personal_website

Design and build an official Apify integration for a company's product - workflow-automation apps (Zapier/n8n-style), AI agent plugins (coding-agent skills+MCP bundles or OpenClaw/Hermes-style harnesses), AI framework packages (LangChain/LlamaIndex-style), or direct application clients via apify-client. Use when planning, creating, or reviewing an integration that exposes Apify Actors, runs, datasets, or key-value stores inside another product.

nehakanjamala/personal_website

Universal AI-powered web scraper for any platform. Scrape data from Instagram, Facebook, TikTok, YouTube, LinkedIn, X/Twitter, Google Maps, Google Search, Google Trends, Reddit, Airbnb, Yelp, and 15+ more platforms. Use for lead generation, brand monitoring, competitor analysis, influencer discovery, trend research, content analytics, audience analysis, review analysis, SEO intelligence, recruitment, or any data extraction task.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a glassmorphism effect", "frosted glass UI", "Apple liquid glass style", "frosted blur card", "translucent glass panel animation", "make a frosted nav bar", "build a glass modal/dialog", "animate a glass card on hover", or "add a refracting liquid-glass hero". Covers frosted translucent panels with backdrop-filter blur, edge/specular highlights, SVG liquid-glass refraction, motion on hover/scroll/enter, and accessible reduced-transparency fallbacks.

nehakanjamala/personal_website

This skill should be used when the user asks to "build a scroll animation", "add ScrollTrigger", "pin a section while scrolling", "scrub an animation to scroll", "create a hero timeline", "do a horizontal scroll section", "split text and animate words", "animate a layout change with GSAP Flip", "sync ScrollTrigger with Lenis", "Lenis smooth scroll jittery", "ScrollTrigger markers drift", "ScrollTrigger pins break with Lenis/Locomotive", or "set up smooth scroll with GSAP pinning". Covers GSAP timelines, ScrollTrigger, SplitText, Flip, and Lenis/Locomotive smooth-scroll sync for code-driven web motion.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a Lottie animation", "play a .lottie or .json animation", "integrate a Bodymovin/After Effects animation on web or mobile", "control Lottie playback / segments", "make a scroll-driven Lottie", "recolor a Lottie at runtime", or "export an AE animation to Lottie". Covers dotLottie/lottie-web integration, playback control, interactivity, theming, and the AE export checklist.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a hover/press effect", "animate a toggle or switch", "build an animated like button", "make a toast/snackbar slide in", "animate a drawer or modal", "animate list reordering or add/remove", "do a shared-element layout transition", or "polish UI feedback". Covers UI motion with Framer Motion (motion/react) and modern CSS.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate page or route transitions", "add a page transition or crossfade between views", "animate route changes in Next.js App Router", "use the View Transitions API", "AnimatePresence exit doesn't fire on navigation", or "Framer Motion exit animation not working / exit animation before unmount in Next.js". Covers enter/exit page-transition animation with the View Transitions API and Framer Motion, for Next.js App Router and general SPA routing.

nehakanjamala/personal_website

Scrape web pages using Scrapling with anti-bot bypass (like Cloudflare Turnstile), stealth headless browsing, spiders framework, adaptive scraping, and JavaScript rendering. Use when asked to scrape, crawl, or extract data from websites; web_fetch fails; the site has anti-bot protections; write Python code to scrape/crawl; or write spiders.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate an SVG", "make a line draw itself on", "do a stroke draw-on / signature animation", "morph one shape into another", "move an element along a path", "animate an icon/logo", or "animate an SVG gradient or filter". Covers stroke-dashoffset draw-on, path morphing, motion-along-path, and animated icons/gradients/filters via CSS, SMIL, and GSAP.

関連スキル