Communitygithub.com

SVGアニメーション

アイコン、イラスト、ロゴ向けのSVGアニメーションスキル。ストローク描画、パスモーフィング、モーションパス、グラデーション/フィルターアニメーションをCSS、SMIL、GSAPで実現します。

SVGアニメーション とは?

このスキルは、SVG要素をCSS、SMIL、またはJavaScript(GSAP)を用いてアニメーションさせるための包括的なガイドです。アイコンやロゴのストローク描画、図形のパスモーフィング、要素の軌道に沿った移動、グラデーションやフィルターのアニメーションなど、多様なアニメーション手法をカバーします。各手法の実装コード例、適切なライブラリの選び方、パフォーマンスの最適化、アクセシビリティ(prefers-reduced-motion対応)まで詳細に説明されています。また、単一のHTMLファイルとして納品するための「シークハーネス」の実装方法や、スクリーンショットによる検証手順も含まれており、実践的な開発ワークフローを提供します。

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

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

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

ドキュメント

SVGアニメーション は何をしますか?

シャープで軽量、無限にスケーラブルなベクターモーション。アイコン、イラスト、ロゴ、データマークに最適です。SVGは3つの方法でアニメーションできます。CSS(宣言的、シンプル)、SMIL(SVG内部の<animate>)、JS(GSAP/Web Animations、制御とモーフィングに優れる)。タスクに応じて適切な手法を選んでください。以下のテクニックが指針を示します。

使用するタイミング

  • アイコン、イラスト、署名、地図のストローク「描画(draw-on)」
  • 図形/パスのモーフィングとアニメーションするアイコンの状態遷移(メニュー↔閉じる、再生↔一時停止)
  • パスに沿った要素の移動(モーションパス)
  • アニメーションするグラデーション、フィルター(グロー、ディスプレイスメント)、アニメーションロゴ

コアテクニック

ストローク描画(基本)

ダッシュ配列をパスの長さに設定し、完全にオフセット(非表示)してから、オフセットを0にアニメーションします。

.path {
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
  animation: draw 1.4s ease forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

長さを取得する方法:

  • JS(最も信頼性が高い): const len = path.getTotalLength(); path.style.setProperty("--len", len);
  • JS不要のテクニック: <path>にpathLength="1"を設定し、stroke-dasharray: 1; stroke-dashoffset: 1;としてから0にアニメーションします。これにより、どのパスも0~1の長さに正規化されるため、計測が不要になります。

消去(逆方向)は、オフセットを0からlenに戻すようにアニメーションします。複数のパスをanimation-delayでずらします。描画の方向はパスの点の順序に従います。逆方向に描画される場合は、エディタでパスの向きを反転するか、オフセットの符号を反転します。

あるパスを別のパスにモーフィング

パスは点ごとに補間されるため、単純なモーフィングでは、両方のd属性が同じ数と種類のコマンドを持つ必要があります。2つの堅牢な方法があります。

  • GSAP MorphSVG(GSAP 3.12以降は無料) — ポイント数が一致しない場合も自動的に処理し、適切なマッピングを見つけます:
gsap.registerPlugin(MorphSVGPlugin);
gsap.to("#start", { morphSVG: "#end", duration: 0.8, ease: "power2.inOut" });
// 任意のシェイプをモーフィング可能なパスに変換:
MorphSVGPlugin.convertToPath("circle, rect, ellipse, line, polygon");
  • Flubber(小さなスタンドアロンライブラリ) — GSAPなしで補間器を生成します。React/Framer Motionと相性が良いです:
import { interpolate } from "flubber";
const interpolator = interpolate(pathA, pathB, { maxSegmentLength: 2 });
// interpolator(0) === pathA, interpolator(1) === pathB; tweenにtを渡します。

手書きのモーフィング(アイコンの切り替えなど)の場合、両方のパスを同一のコマンド構造で維持し、dをWeb AnimationsまたはCSSで直接アニメーションします(dは最新ブラウザではpath("...")経由でアニメーション可能です)。

パスに沿ったモーション

  • GSAP MotionPath(推奨 — 制御、配置、スクラブ対応):
gsap.registerPlugin(MotionPathPlugin);
gsap.to("#rocket", {
  duration: 4, repeat: -1, ease: "none",
  motionPath: { path: "#track", align: "#track", autoRotate: true, alignOrigin: [0.5, 0.5] },
});

autoRotate: trueはオブジェクトをパスの接線方向に向けます。alignは座標をパス要素に相対的にします。

  • SMIL(JS不要):
<path id="track" d="M10,80 C40,10 120,10 150,80" fill="none"/>
<circle r="6" fill="#3b82f6">
  <animateMotion dur="3s" repeatCount="indefinite" rotate="auto">
    <mpath href="#track"/>
  </animateMotion>
</circle>
  • CSS offset-path(最新、宣言的): offset-path: path("M10,80 C..."); animation: move 3s linear infinite; に @keyframes move { to { offset-distance: 100%; } } と offset-rotate: auto を組み合わせます。

アニメーションするグラデーションとフィルター

グラデーション: gradientTransformまたはストップオフセットをアニメーションします。シーン(光沢)スイープの例:

<linearGradient id="sheen">
  <stop offset="0%"  stop-color="#fff" stop-opacity="0"/>
  <stop offset="50%" stop-color="#fff" stop-opacity=".8"/>
  <stop offset="100%" stop-color="#fff" stop-opacity="0"/>
  <animateTransform attributeName="gradientTransform" type="translate"
    from="-1 0" to="1 0" dur="2s" repeatCount="indefinite"/>
</linearGradient>

フィルター: feDisplacementMapのscaleで粘り気/揺れ、feGaussianBlurのstdDeviationでフォーカス移動、feColorMatrix/feFloodでグローをアニメーションします。フィルターは描画負荷が高いため、控えめにアニメーションし、可能な限りtransform/opacityを優先します。

実装の選択(素早く選ぶ)

要件使用するもの
単一の宣言的な描画/フェードCSS
自己完結型、JSバンドル不要SMIL(SVG内の<animate*>)
連携、スクラブ可能、スクロール連動GSAP
ポイント不一致のモーフィングGSAP MorphSVG または Flubber
回転を伴うパス追従GSAP MotionPath / CSS offset-path

SMILの注意点: IE/古いEdgeではサポートされておらず、歴史的に非推奨フラグが立っています。最大のリーチやスクロール同期が必要な場合は、CSSまたはJSを優先してください。それでも、SMILは最新ブラウザでの自己完結型アイコンアセットには問題なく使用できます。

作成と最適化

  • SVGOでのビルド/クリーニング: viewBoxを維持し、エディタのメタデータを削除しますが、cleanupIds/removeViewBoxや、CSS/JS/SMILから参照しているIDをリネームするプラグインは無効にします。個々のサブパスやシェイプをアニメーションする場合は、mergePathsとconvertShapeToPathも無効にします。
  • SVGをDOMにインライン化します(<img src>ではありません)。CSS/JSが内部にアクセスできるようにするためです。<img>に埋め込まれたSVGは、内部のSMIL/CSSで自己アニメーションするのみです。
  • 明示的なviewBoxを設定し、固定のwidth/heightを避けることで、アセットが流動的にスケーリングされます。
  • 描画では、パスが実際のストローク(fill:none; stroke:...)であり、塗りつぶしされた輪郭ではないことを確認します。dashoffsetはストロークにのみ影響します。
  • prefers-reduced-motionを尊重します。ループや大きなモーションを制限し、静的な最終状態を維持します。

納品と検証(スタンドアロン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ファイルです。マークアップにSVGをインライン化し、1つのメカニズムでアニメーションを駆動し、ビルドステップは不要です。ベクターアセットとしては1ファイルが適切です。バンドラーに頼らないでください。

出力契約:

  • 1つの.htmlファイル: インライン<svg>、CSS @keyframes / CDNからのGSAPを含む<script> / SMIL <animate*> — 1つのドライバーを選択します。
  • そのドライバーに対応するシークハーネスを含め、任意の瞬間をスクリーンショット用に固定できるようにします。

シークハーネス — 正確な瞬間を固定。 ?t=Nでシークして一時停止し、スクリーンショットが静止フレームを捉えるようにします。SVGのアニメーション方式に合わせたメカニズムを使用します:

<script>
  const t = new URLSearchParams(location.search).get("t");
  if (t !== null) {
    const N = parseFloat(t);
    // SMIL: SVG自身のクロックを一時停止してスクラブ
    const svg = document.querySelector("svg");
    svg.pauseAnimations(); svg.setCurrentTime(N);
    // CSS @keyframes 描画: el.style.animationDelay=(-N)+"s"; el.style.animationPlayState="paused";
    // GSAP タイムライン: tl.pause(); tl.seek(N);
  }
  window.__ready = true;
</script>

検証ループ — レンダリング→固定→スクリーンショット→確認: 開始/中間/終了(?t=0、?t=<dur/2>、?t=<dur>)でファイルを開き、それぞれをスクリーンショットして、忠実度(ストロークが正しい方向に描画されているか、モーフィングの端点がきれいか)とアーティファクト(パスがviewBoxでクリップされていないか、古いdashoffsetでストロークが消失していないか、FOUC、モーフィングの継ぎ目でのジャンク)を確認します。ヘッドレスツールはどれでも動作します:

npx playwright screenshot --wait-for-timeout=500 "file://$PWD/icon.html?t=0.7" frame-mid.png

終了前の確認事項:

  1. スタンドアロンで開く — コンソールエラーなし、インラインSVGにアクセス可能、CDN(ある場合)が読み込まれる。
  2. 使用ドライバーに対応するシークメカニズムが、決定論的なフレームを固定できる。
  3. 開始/中間/終了でスクリーンショットを撮影 — 要件に合致し、クリッピングやviewBox外のストロークがない。
  4. prefers-reduced-motionが尊重されている — ループ/大きなモーションが制限され、静的な最終状態が保持されている。
  5. イージングが意図的である — ease/GSAPイージングが意図的に選択され、不注意によるlinear描画がない。

参考ファイル

  • references/svg-techniques.md — 完全なdashoffsetの計算とgetTotalLengthの注意点、pathLength="1"による正規化、GSAP MorphSVGとFlubberの選択ガイド(コード付き)、アイコン切り替えモーフィング(ハンバーガー↔閉じる)、MotionPath/offset-pathの詳細、SMIL対CSS対JSのトレードオフ、アニメーション用に調整されたSVGO設定。

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

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.

関連スキル