Communitygithub.com

nehakanjamala/personal_website

当用户要求“为SVG添加动画”、“让线条自行绘制”、“实现描边绘制/签名动画”、“将一个形状变形为另一个”、“让元素沿路径移动”、“为图标/Logo添加动画”或“为SVG渐变或滤镜添加动画”时,应使用此技能。涵盖通过CSS、SMIL和GSAP实现的描边虚线偏移绘制、路径变形、沿路径运动以及图标/渐变/滤镜动画。

personal_website 是什么?

此技能专注于使用CSS、SMIL(SMIL动画)和GSAP(GreenSock动画平台)三种主要方式为SVG(可缩放矢量图形)文件添加动画效果。它非常适合制作图标、插画、Logo和数据标记的动画,提供轻量级、清晰且无限缩放的矢量运动。技能详细讲解了核心动画技术,包括使用`stroke-dasharray`和`stroke-dashoffset`的描边绘制动画、处理路径变形的不同策略(如GSAP MorphSVG插件或Flubber库)、使用GSAP MotionPath插件或CSS `offset-path`属性实现的沿路径运动,以及动态渐变和滤镜的动画。每种技术都对应不同的使用场景,技能中提供了清晰的决策指南。技能还强调了SVG创作和优化实践,例如使用SVGO进行构建和清理、在DOM中内联SVG以便CSS/JS访问,以及设置明确的`viewBox`。最后,它提供了一个健壮的交付验证方案,包含一个“seek harness”机制,可通过URL参数(`?t=N`)定格动画的特定帧,并使用Playwright或类似工具进行截图验证,确保动画质量。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/nehakanjamala/personal_website/tree/HEAD/.agents/skills/svg-animation

在你喜欢的 AI 中提问

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

文档

SVG 动画

清晰、轻量、无限可扩展的矢量运动——极为适合图标、插图、Logo 和数据标记。SVG 可通过三种方式实现动画:CSS(声明式、简单)、SMIL(在 SVG 内部使用 <animate>)和 JS(GSAP/Web Animations,适合控制和变形)。根据任务选择;下面的技术会说明各自适用场景。

使用时机

  • 图标、插图、签名、地图的描边“绘制”动画
  • 形状/路径变形和动画图标状态切换(菜单 ↔ 关闭,播放 ↔ 暂停)
  • 沿路径移动元素(运动路径)
  • 动画渐变、滤镜(发光、位移)以及动画 Logo

核心技术

描边绘制(核心技巧)

将虚线数组设置为与路径等长,偏移量设置为全长(不可见),然后将偏移量动画到 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 属性具有相同数量和类型的命令。两种稳健的方法:

  • 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; 将 t 值传入一个补间函数。

对于手动编写的变形(如图标切换),保持两个路径具有相同的命令结构,并通过 Web Animations 或 CSS 直接对 d 属性进行动画(在现代化浏览器中可通过 path("...") 对 d 进行动画)。

沿路径运动

  • 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。
  • 在 DOM 中内联 SVG(不要使用 <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。

对于自包含的图标/Logo/绘制动画,交付物是一个可以直接在浏览器中打开的 HTML 文件——在标记中内联 SVG,使用一种机制驱动动画,无需构建步骤。一个文件就是矢量资产的合适层级;无需使用打包工具。

输出约定:

  • 一个 .html 文件:内联 <svg>,加上 CSS @keyframes / 一个包含来自 CDN 的 GSAP 的 <script> / SMIL <animate*> —— 选择一种驱动方式。
  • 包含与该驱动匹配的 seek harness,以便可以冻结任意时刻进行截图。

Seek harness —— 冻结精确时刻。 ?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. 与你的驱动匹配的 seek 机制能冻结一个确定的帧。
  3. 在开始/中间/结束时截图 —— 与需求匹配、没有裁剪或超出 viewBox 的描边。
  4. 遵循 prefers-reduced-motion —— 限制循环/大幅运动、保留静态最终状态。
  5. 缓动函数是经过有意选择的 —— 有目的地选择 ease/GSAP 缓动,避免意外的 linear 绘制动画。

参考文件

  • references/svg-techniques.md —— 完整的 dashoffset 数学计算和 getTotalLength 注意事项、pathLength="1" 归一化、GSAP MorphSVG 与 Flubber 决策指南及代码(包含图标切换变形(hamburger↔close))、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.

相关技能