Communitygithub.com

パフォーマンス重視のWebアニメーション

CSSアニメーションにおいて、レイアウトやペイントを引き起こすプロパティではなく、コンポジットのみで動作する`transform`と`opacity`を使った効率的なアニメーション手法を提供するスキルです。

パフォーマンス重視のWebアニメーション とは?

このスキルは、Webアニメーションのパフォーマンス問題、特にカクつき(ジャンク)の主要原因である、ブラウザにレイアウトの再計算(リフロー)や再描画(ペイント)を強制するプロパティのアニメーションを排除するための実践的ガイドです。ブラウザのレンダリングパイプライン(レイアウト→ペイント→コンポジット)を理解し、`transform`と`opacity`のみをアニメーションさせることで、アニメーションをGPU上のコンポジタで処理し、スムーズな60fps/120fpsを実現します。具体的には、`width`/`height`の代わりに`transform: scale()`を、`top`/`left`の代わりに`transform: translate()`を使う方法や、`box-shadow`を疑似要素の`opacity`アニメーションに置き換えるテクニック、レイアウト変更をコンポジタでアニメーションするFLIP技法、`height: auto`のアニメーション方法、レイアウトスラッシングの回避策、`will-change`の適切な使用法などをカバーします。各テクニックにはコード例とともに、DevTools Performanceパネルを使った検証方法(Layout/Paintバーが表示されないことの確認)も含まれています。このスキルはClaude Code、Cursor、CodexなどのAIエージェントで使用でき、開発者がパフォーマンスの高いWebアニメーションを実装する際の強力なリファレンスとなります。

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

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

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

ドキュメント

パフォーマンス重視のWebアニメーション は何をしますか?

Webアニメーションのカクつきの最大の原因を排除します。それは、ブラウザに毎フレームレイアウトの再計算(リフロー)や再描画(ペイント)を強制するプロパティをアニメーションすることです。ブラウザのレンダリングは レイアウト → ペイント → コンポジット の段階で行われます。width、height、top、left、margin、padding、box-shadow、filter をアニメーションすると、毎フレームレイアウトやペイントが再実行され、メインスレッドをブロックします。transform と opacity をアニメーションすると、レイアウトとペイントをスキップし、コンポジタ(多くの場合GPU)でのみ実行されるため、60/120fpsでスムーズなアニメーションが実現します。

使用するタイミング

アニメーションがカクついたりフレームドロップする場合、ホバー/スクロールエフェクトが重く感じられる場合、サイズ/位置/シャドウをアニメーションする場合、レイアウト変更(カードの並び替え、要素のコンテナ間移動など)をスムーズにアニメーションする必要がある場合、height: auto をアニメーションする場合、またはアニメーションコードのパフォーマンスをレビューする場合に使用します。

基本ルール: transform と opacity のみをアニメーションする

すべての「高コストな」アニメーションを、同等の低コストなものにマッピングします。

アニメーション対象(高コスト)トリガー置き換え(低コスト)
width / heightレイアウト + ペイントtransform: scaleX()/scaleY() (+ 真のサイズ変更にはFLIP)
top / left / marginレイアウト + ペイントtransform: translate()
box-shadowペイントシャドウを保持する疑似要素の opacity をアニメーション
filter: blur()ペイント(高負荷)2つのレイヤーを opacity でクロスフェード、または控えめに使用
background-positionペイント子レイヤーで transform: translate()
color / backgroundペイント多くの場合許容範囲内。またはレイヤーのクロスフェード

位置とサイズは transform で

/* 悪い例: 毎フレームレイアウトをアニメーション */
.box { transition: left 300ms, width 300ms; left: 0; width: 100px; }
.box:hover { left: 200px; width: 200px; }

/* 良い例: コンポジタのみ */
.box {
  transition: transform 300ms ease;
  transform: translateX(0) scaleX(1);
  transform-origin: left center;
}
.box:hover { transform: translateX(200px) scaleX(2); }

scaleX は内部のコンテンツ(テキスト)を歪めます。歪みのない真のリサイズには FLIP を使用します。

疑似要素のopacityを使った低コストなbox-shadow

box-shadow をアニメーションすると、毎フレーム広範囲のぼかし領域が再描画されます。代わりに、::after 疑似要素にシャドウを一度だけ描画し、その opacity のみをアニメーションします。

.card { position: relative; }
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 300ms ease;
  pointer-events: none;
}
.card:hover::after { opacity: 1; }

ぼかしシャドウは一度ラスタライズされ、ホバーではコンポジタのopacityのみが変化するため、どのフレームレートでもスムーズです。

FLIP: レイアウト変更を低コストでアニメーション

FLIP(First, Last, Invert, Play)は、transform のみを使用してレイアウトの変更(並び替え、リサイズ、コンテナ間の移動)をアニメーションします。要素の元の位置(First)と最終位置(Last)を計測し、反転(Invert)するtransformを適用して視覚的に動いていないように見せ、その後transformを元に戻す(Play)アニメーションを行います。DOMは実際の最終レイアウトに配置され、動きは純粋なコンポジタ処理のみで実行されます。

function flip(el, mutate) {
  const first = el.getBoundingClientRect();   // First
  mutate();                                    // DOM/レイアウトを変更
  const last = el.getBoundingClientRect();     // Last

  const dx = first.left - last.left;
  const dy = first.top - last.top;
  const sx = first.width  / last.width;
  const sy = first.height / last.height;

  el.animate(
    [
      { transformOrigin: 'top left',
        transform: `translate(${dx}px, ${dy}px) scale(${sx}, ${sy})` }, // Invert
      { transformOrigin: 'top left', transform: 'none' },               // Play
    ],
    { duration: 300, easing: 'cubic-bezier(0.2, 0, 0, 1)' }
  );
}

// 使用例: 要素を新しいグリッド位置に移動するアニメーション
flip(card, () => targetContainer.appendChild(card));

Web Animations API の animate() は transform をコンポジタで実行します。複数の要素がある場合は、すべての getBoundingClientRect() の読み取りをすべてのミューテーションの前にバッチ処理してください(下記のレイアウトスラッシングを参照)。

height: auto のアニメーション

height: auto は従来、補間可能ではありませんでした。モダンな方法とフォールバック方法を以下に示します。

/* モダン(Chrome 129+/対応ブラウザ): サイズキーワードをアニメーション可能にする */
.panel {
  interpolate-size: allow-keywords;   /* autoとの間のアニメーションを有効にする */
  height: 0;
  overflow: clip;
  transition: height 300ms ease;
}
.panel.open { height: auto; }
/* calc-size() も利用可能: height: calc-size(auto, size); */
/* 現在の堅牢なフォールバック: CSS grid 1fr -> 0fr */
.wrapper {
  display: grid;
  grid-template-rows: 0fr;            /* 折りたたみ */
  transition: grid-template-rows 300ms ease;
}
.wrapper.open { grid-template-rows: 1fr; }
.wrapper > .content { overflow: hidden; min-height: 0; }

グリッドのトリックはトラックサイズをアニメーションします(コンポジタに優しく、広くサポートされています)。JSによる高さの計測は不要です。ターゲットブラウザがサポートしている場合は interpolate-size: allow-keywords / calc-size(auto, size) を使用し、クロスブラウザのデフォルトとしてグリッドテクニックを維持します。

レイアウトスラッシングを避ける(読み取りをバッチ処理し、その後書き込み)

書き込みの後にレイアウトプロパティ(offsetWidth、getBoundingClientRect、scrollTop、getComputedStyle)を読み取ると、同期的なリフローが強制されます。ループ内で読み取りと書き込みを交互に行うと(「レイアウトスラッシング」)、1フレームあたり何十もの強制リフローが発生する可能性があります。

// 悪い例: 読み取り、書き込み、読み取り、書き込み... イテレーションごとにリフローを強制
items.forEach((el) => {
  const w = el.offsetWidth;          // 読み取り(レイアウトを強制)
  el.style.width = w * 1.5 + 'px';   // 書き込み(レイアウトを無効化)
});

// 良い例: すべての読み取りをバッチ処理し、その後すべての書き込み
const widths = items.map((el) => el.offsetWidth);  // すべての読み取り
items.forEach((el, i) => {                          // すべての書き込み
  el.style.width = widths[i] * 1.5 + 'px';
});

フレーム同期処理の場合、requestAnimationFrame コールバック内で読み取り、書き込みを適用します。fastdom のようなライブラリは、この読み取り/書き込みスケジューリングを正式なものにしています。

will-change: 控えめに使用する

will-change: transform は、あらかじめ要素を独自のコンポジタレイヤーに昇格させ、アニメーション開始時の処理落ち(ヒッチ)を防ぎます。ただし、昇格されたレイヤーはGPUメモリを消費するため、過剰に使用するとパフォーマンスが低下します。

.menu { will-change: transform; }   /* アニメーションする要素にのみ適用 */

ルール: アニメーションの直前にのみ適用し(例: ホバー時や親状態)、アイドル時には削除する(will-change: auto)、多くの要素に一律に適用しない、多数の/大規模なノードに永続的に残さない。transform: translateZ(0) ハックも同じ昇格を行いますが、元に戻すのが難しいため、will-change を使用することを推奨します。

成果物の作成と検証(スタンドアロン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アニメーション、フリーズ用ハーネスを1ファイルに含めます。このスキルでは、検証は二段階です。フレームが正しく見えることおよびその生成が低コスト(コンポジタのみ)であること。

出力契約:

  • 1つの .html、依存関係はCDN経由で任意、アニメーションはCSS transitions/@keyframes またはWeb Animations APIで駆動。
  • スクリーンショットが決定論的なフレームに固定されるフリーズ機構:
    • CSS @keyframes → ?t=N で el.style.animationDelay = (-N)+'s'; el.style.animationPlayState = 'paused' を設定。
    • WAAPI / JS → アニメーションオブジェクトを保持し、anim.pause(); anim.currentTime = N*1000 を実行。

検証ループ — フリーズ → スクリーンショット、その後ジャンクのプロファイリング:

  1. 開始/中間/終了時点でヘッドレスで開き(?t=0、中間、終了)、それぞれスクリーンショットを取得。動きが視覚的に正しいことを確認(scaleX によるテキストのクリップや伸縮がない、FLIPが実際のレイアウトに正しく着地する、シャドウ/高さのトランジションが適切に見える)。
  2. コンポジタのみであることを確認 — このスキルの要点です。以下のいずれかで確認:
    • DevTools → Performance: アニメーションを録画し、各フレームに紫色の「Layout」や緑色の「Paint」バーがないこと(「Composite Layers」のみ)を確認。
    • またはヘッドレストレース: npx playwright screenshot でビジュアルを取得し、CDP/tracing キャプチャでアニメーションウィンドウ中に Layout/Paint イベントが発生しないことをアサート。
  3. FPS/「Frame Rendering Stats」オーバーレイが60のままであることを確認 — フレームドロップは高コストなプロパティが混入したことを意味します。
npx playwright screenshot --wait-for-timeout=500 "file://$PWD/anim.html?t=0.3" frame.png

終了前の確認事項:

  1. スタンドアロンで開く — コンソールエラーなし。
  2. 毎フレーム transform / opacity のみがアニメーションする。DevToolsでフレームごとのLayout/Paintが表示されない。
  3. 開始/中間/終了でスクリーンショット取得 — 正しい、scaleX によるテキストの歪みがない、FLIPが正しく着地する。
  4. 60fpsを維持。will-change はジャストインタイムで適用され、アイドル時に削除される(残存レイヤーなし)。
  5. prefers-reduced-motion が尊重されている。

クイックリファレンス

目標実行内容
要素を移動transform: translate()
歪みなくリサイズFLIP + transform
ホバー時のシャドウシャドウ疑似要素の opacity をアニメーション
コンテンツ高さに展開grid 0fr→1fr、または interpolate-size: allow-keywords
多数の要素を移動getBoundingClientRect の読み取りをバッチ処理し、その後書き込み
スムーズなアニメーション開始will-change をジャストインタイムで適用、アイドル時に削除
コンポジタのみの確認DevTools Performance: フレームごとに紫色の「Layout」/緑色の「Paint」がないこと

注意点(Gotchas)

  • scaleX/scaleY はテキストと子要素を伸ばします。コンテンツを鮮明に保つ必要がある場合はFLIPを使用してください。
  • transform のパーセンテージ値は要素自身のボックスを基準にします(親ボックス基準の left: % とは異なります)。
  • will-change や translateZ(0) の過剰使用はレイヤーを増やしすぎてパフォーマンスを低下させます。アニメーションする要素だけを昇格させてください。
  • filter と backdrop-filter はコンポジタ関連ですが、依然として高コストです。ぼかし半径をアニメーションするのではなく、opacityのクロスフェードでそれらの有無をアニメーションしてください。
  • grid 1fr→0fr のコンテンツには overflow: hidden と min-height: 0 が必要です。そうしないと折りたたまれません。
  • 必須でない動きは常に @media (prefers-reduced-motion: reduce) でガードしてください。

参考ファイル

  • references/patterns-and-profiling.md — 完全な実行可能な例(アコーディオン、リストの並び替え、パララックス)、コンポジタのみのフレームを確認するためのDevToolsプロファイリングのチュートリアル、動き軽減パターン、プロパティコストのチートシート。

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 "respect prefers-reduced-motion", "honor reduced motion", "make my animations accessible", "fix vestibular / motion-sickness issues", "add a useReducedMotion hook", "gate GSAP / Framer Motion / Lenis for reduced motion", or "meet WCAG 2.3.3 / C39". Provides tiered (not all-or-nothing) reduced-motion patterns in CSS and JS.

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.

関連スキル