Communitygithub.com

nehanakamala/personal_website

该技能适用于用户需要“添加 Lottie 动画”、“播放 .lottie 或 .json 动画”、“在 Web 或移动端集成 Bodymovin/After Effects 动画”、“控制 Lottie 播放/片段”、“制作滚动驱动的 Lottie”、“在运行时重新着色 Lottie”或“将 AE 动画导出为 Lottie”的场景。涵盖了 dotLottie/lottie-web 集成、播放控制、交互、主题设置以及 AE 导出清单。

personal_website 是什么?

该技能是一个关于 Lottie 动画(Lottie Animation)的全面指南,Lottie 是一种从 After Effects 到产品的桥梁,以 JSON 或压缩的 .lottie 格式传输矢量动画,具有体积小、分辨率无关的特点,可在 Web、iOS、Android 和 React Native 上通过运行时播放。技能详细介绍了 Lottie 的适用场景,例如循环插图、引导页、空状态、动画图标以及基于滚动或交互的播放。它解释了 .json 和 .lottie 格式的区别,并推荐使用更现代的 dotLottie 运行时。技能提供了在 Web 上集成和播放 Lottie 动画的具体代码示例,包括使用 vanilla JavaScript 和 React 的方式。此外,还涵盖了播放控制(如播放、暂停、停止、设置速度、模式、帧和片段)、滚动驱动的动画(无需 GSAP)、运行时主题/重新着色、移动端 API 的快速参考、性能优化建议,以及如何交付一个独立的 HTML 测试文件并进行截图验证。用户可以通过该技能快速掌握从 After Effects 导出 Lottie 动画到在多种平台上集成和定制的完整工作流。

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

在你喜欢的 AI 中提问

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

文档

Lottie 动画

从 After Effects 到产品的桥梁:矢量动画以 JSON(或压缩的 .lottie)格式传输,体积小且分辨率无关,由 Web、iOS、Android 和 React Native 上的运行时播放。此技能涵盖 Lottie 的集成、控制和导出。

使用时机

  • 将设计师的 AE 动画交付到 Web/iOS/Android/React Native
  • 循环插图、引导页、空状态、动画图标
  • 滚动驱动或交互驱动的矢量播放(悬停、点击、光标)
  • 运行时主题/重新着色,而不是为每个品牌重新导出

格式:.json 与 .lottie

  • .json — 原始的 Bodymovin 输出。可读性高,文件较大。
  • .lottie — 压缩容器(通常小 60–80%),可捆绑多个动画、图像和主题。推荐用于交付。播放器:@lottiefiles/dotlottie-web(现代,基于 canvas + WASM)取代了较旧的 lottie-web。

对于新项目,推荐使用 dotLottie 运行时;仅在需要旧版 .json + SVG 渲染器时使用 lottie-web。

核心工作流(Web,dotLottie)

npm i @lottiefiles/dotlottie-web        # 原生
npm i @lottiefiles/dotlottie-react      # React 封装

原生:

import { DotLottie } from "@lottiefiles/dotlottie-web";

const dotLottie = new DotLottie({
  canvas: document.querySelector("#lottie"),  // 一个 <canvas> 元素
  src: "/hero.lottie",                         // 或 .json
  loop: true,
  autoplay: true,
  // speed: 1, mode: "forward" | "reverse" | "bounce", renderConfig: { autoResize: true }
});

React:

import { DotLottieReact } from "@lottiefiles/dotlottie-react";

function Hero() {
  return <DotLottieReact src="/hero.lottie" loop autoplay style={{ width: 320 }} />;
}

捕获实例以控制它:

const [dl, setDl] = useState(null);
<DotLottieReact src="/icon.lottie" dotLottieRefCallback={setDl} />;
// dl?.play(); dl?.pause(); dl?.setSpeed(2);

播放控制

dotLottie.play();
dotLottie.pause();
dotLottie.stop();
dotLottie.setSpeed(1.5);
dotLottie.setMode("bounce");        // forward | reverse | bounce | reverse-bounce
dotLottie.setFrame(42);             // 跳转到某帧
dotLottie.setSegment(30, 90);       // 将播放限制在某个帧范围内(例如“加载中”循环)

事件驱动序列和 UI:

dotLottie.addEventListener("load", () => { /* 现在可以获取 totalFrames */ });
dotLottie.addEventListener("complete", () => { /* 非循环播放完成 */ });
dotLottie.addEventListener("frame", ({ currentFrame }) => { /* 每帧 */ });

状态机模式(例如,播放“已勾选”片段然后空闲的按钮):播放一个片段,监听 complete 事件,然后 setSegment 到空闲循环。

滚动驱动的 Lottie(无需 GSAP)

将滚动进度(0-1)映射到帧。暂停自动播放,自己驱动帧。

const dotLottie = new DotLottie({ canvas, src: "/scroll.lottie", autoplay: false });
let total = 0;
dotLottie.addEventListener("load", () => { total = dotLottie.totalFrames; });

window.addEventListener("scroll", () => {
  const el = canvas.closest(".scrolly");
  const rect = el.getBoundingClientRect();
  const p = clamp(-rect.top / (rect.height - window.innerHeight), 0, 1); // 滚动经过该区域时 0..1
  dotLottie.setFrame(p * (total - 1));
}, { passive: true });

const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));

对于更丰富的交互(悬停播放、点击切换、光标跟随),而无需手动编写连接代码,可以使用 @lottiefiles/lottie-interactivity,它可以将 scroll、hover、click、play 和 cursor 模式声明式地映射到帧范围。

运行时主题/重新着色

两种路径:

  • dotLottie 主题:一个 .lottie 可以嵌入命名的颜色主题;使用 dotLottie.setTheme("dark") 或 loadTheme(...) 切换。在 LottieFiles 工具中编写 — 无需重新导出即可重新着色。
  • 手动颜色覆盖:加载 JSON,遍历 layers[].shapes[] 并修补 c.k 颜色数组(归一化的 0-1 范围 RGBA),然后用修改后的对象初始化播放器。这种方法脆弱(依赖于图层结构)—— 当需要通过 CSS 驱动的 SVG 渲染器(lottie-web rendererSettings)按类重新样式化时,优先选择主题。

移动端运行时(功能一致)

  • iOS — lottie-ios(LottieAnimationView):.play()、.currentProgress、.play(fromFrame:toFrame:)。
  • Android — lottie-android(LottieAnimationView / Compose LottieAnimation):setMinAndMaxFrame、progress。
  • React Native — lottie-react-native(<LottieView source={...} progress={anim} />,使用 Animated 驱动 progress)。

相同的 .lottie/.json 可在所有平台上播放;片段和进度概念与 Web API 一致。

优化

  • 交付 .lottie(压缩)而非原始 .json;懒加载屏幕外的播放器,并在不可见时暂停(IntersectionObserver → play/pause)。
  • 对于大量同时播放的动画,优先使用基于 canvas/WASM 的 dotLottie 渲染器;对于单个清晰的图标,SVG 渲染器(lottie-web)可以满足需求,但对于复杂文件会占用更多 DOM 资源。
  • 保持 AE 合成小:更少的图层/关键帧,不嵌入大位图;尽可能展平预合成。文件大小取决于关键帧和路径复杂度,而非时长。
  • 在运行时重新着色(主题),而不是为每个品牌/主题导出一个文件。

交付与验证(独立 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。

对于自包含的 Lottie 演示(循环插图、动画图标、空状态),交付物是一个可直接在浏览器中打开的 HTML 文件 —— 来自 CDN 的 dotLottie/lottie-web 运行时、一个 <canvas> 元素以及您的 .lottie/.json 文件(相对路径或 data URL)。无需构建步骤。单个文件是交付播放器的合适层级;不要使用打包工具。

输出协定:

  • 一个 .html 文件:通过 CDN 引入的运行时(@lottiefiles/dotlottie-web)、canvas 元素,以及 autoplay:false,以便您可以自行控制帧。
  • 包含一个查找测试工具,以便任何帧都可以被冻结用于截图。

查找测试工具 — 冻结精确帧。?t=N 跳转到某一帧并保持,以便截图能够捕捉到静止、确定性的帧。Lottie 的播放头基于帧,因此直接在目标帧上停止:

<script>
  const dl = new DotLottie({ canvas, src: "/icon.lottie", autoplay: false });
  dl.addEventListener("load", () => {
    const t = new URLSearchParams(location.search).get("t");
    if (t !== null) dl.setFrame(parseFloat(t));      // 冻结在帧 N 上(lottie-web: anim.goToAndStop(N, true))
    else dl.play();
    console.log("totalFrames", dl.totalFrames);       // 读取结束帧
    window.__ready = true;
  });
</script>

验证循环 — 渲染 → 冻结 → 截图 → 检查: 在第一帧/中间帧/最后一帧打开文件(?t=0、?t=<total/2>、?t=<total-1>;从控制台读取 totalFrames),截取每帧截图,并检查保真度(颜色/主题正确,片段按预期循环)以及瑕疵(canvas 因缺少 autoResize/DPR 而模糊、合成被裁剪、文件加载前的 FOUC、卡顿)。任何无头工具都可以:

npx playwright screenshot --wait-for-timeout=600 "file://$PWD/lottie.html?t=42" frame-mid.png

完成前:

  1. 可独立打开 — 无控制台错误,CDN 运行时和 .lottie/.json 文件正常加载。
  2. ?t=N(setFrame/goToAndStop)冻结了正确的、确定性的帧。
  3. 在第一帧/中间帧/最后一帧截屏 — 符合要求,清晰,无裁剪。
  4. 尊重 prefers-reduced-motion — 不要 autoplay 循环;显示静态帧或提供播放控件。
  5. 缓动是经过深思熟虑的 — 播放速度/片段是有意选择的,在 AE 中烘焙的运动按设计呈现。

快速参考

目标调用方法
播放一个范围setSegment(start, end)
跳转到某一帧setFrame(n)
反向 / 反弹`setMode("reverse"
滚动驱动autoplay:false + setFrame(p*totalFrames)
切换主题setTheme("dark")
获取时长load 事件后的 totalFrames
声明式交互@lottiefiles/lottie-interactivity

参考文件

  • references/integration-and-export.md — 包含完整的 dotLottie-web + React 设置、事件/片段控制、lottie-interactivity 模式配置、滚动/光标模式、运行时主题细节,以及完整的 After Effects → Bodymovin 导出清单,其中列出了不支持的 AE 功能及解决方法。

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 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.

相关技能