Communitygithub.com

nehakanjamala/personal_website

此技能用于处理用户关于“构建滚动动画”、“添加 ScrollTrigger”、“固定部分随滚动”、“将动画与滚动同步”、“创建主角时间线”、“水平滚动部分”、“分割文本并逐词动画”、“使用 GSAP Flip 动画化布局变化”、“将 ScrollTrigger 与 Lenis 同步”、“Lenis 平滑滚动卡顿”、“ScrollTrigger 标记漂移”、“ScrollTrigger 固定与 Lenis/Locomotive 冲突”或“设置平滑滚动与 GSAP 固定”等请求。涵盖 GSAP 时间线、ScrollTrigger、SplitText、Flip 以及 Lenis/Locomotive 平滑滚动同步,适合代码驱动的网页动画。

personal_website 是什么?

此技能提供了一套全面的指南,用于在现代 Web 开发中使用 GSAP(GreenSock 动画平台)。它涵盖了核心概念,如时间线(Timeline)优先、ScrollTrigger 滚动驱动动画、SplitText 文本拆分、Flip 布局过渡,以及 Lenis 或 Locomotive 平滑滚动与 ScrollTrigger 的同步。文档详细解释了常见问题的解决方法(如卡顿、标记漂移、固定失效),并提供了清晰的最佳实践,包括性能优化、SPA 清理(使用 gsap.context)以及完整的可运行 HTML 交付模板。此技能适用于在 Claude Code、Cursor、Codex 等 AI 代理环境中,帮助用户快速生成或调试基于 GSAP 的复杂 Web 动画。

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

在你喜欢的 AI 中提问

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

文档

GSAP for the Web (网页 GSAP)

GSAP(GreenSock 动画平台)是代码驱动网页动画的主力工具:序列化时间线、滚动驱动的故事叙述、文本揭示和布局过渡。自 GSAP 3.12+ 起,所有插件(ScrollTrigger、SplitText、Flip、MotionPath、MorphSVG、Draggable、Observer)均完全免费,包括商业使用。

何时使用

  • 滚动驱动的故事叙述:固定部分、视差、进度擦洗、水平滚动
  • 序列化主角动画和复杂的多元素时间线,带有精确的重叠控制
  • 将文本拆分为字符/单词/行进行揭示(SplitText)
  • 元素改变位置/大小/父容器的布局过渡(Flip)
  • 任何需要精细时间控制、缓动精度或命令式编排的动画

安装与注册

import gsap from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { SplitText } from "gsap/SplitText";
import { Flip } from "gsap/Flip";

gsap.registerPlugin(ScrollTrigger, SplitText, Flip);

插件必须在使用前注册,否则会静默失效。使用打包工具时,在应用入口注册一次即可。

核心技术

优先使用时间线

优先使用一条时间线而非多个独立的补间——它提供一个统一的播放头、相对定位,并且易于反转。

const tl = gsap.timeline({ defaults: { ease: "power3.out", duration: 0.6 } });
tl.from(".title", { yPercent: 100, opacity: 0 })
  .from(".sub",   { y: 20, opacity: 0 }, "-=0.3")  // 在前一个补间结束前 0.3 秒开始
  .from(".cta",   { scale: 0.9, opacity: 0 }, "<"); // 与前一个补间的起始对齐

位置参数速查:

  • "+=0.5" / "-=0.3" — 相对于时间线末尾(间隙/重叠)
  • "<" — 前一个补间的开始;">" — 前一个补间的结束
  • "<0.2" — 前一个补间开始后 0.2 秒
  • "myLabel" — 通过 tl.addLabel("myLabel") 添加的命名标签

使用 .from() 进行入场(从给定值动画到当前 CSS),.to() 进行退场,.fromTo() 在需要明确指定两端值时使用(对重复运行最稳定)。

gsap.to vs set vs quickTo

gsap.set(el, { autoAlpha: 0 });           // 即时设置,无补间(autoAlpha = opacity + visibility)
const xTo = gsap.quickTo(el, "x", { duration: 0.4, ease: "power3" });
window.addEventListener("pointermove", (e) => xTo(e.clientX)); // 快速重复更新

autoAlpha 优于原始 opacity,因为它在值为 0 时还会切换 visibility:hidden,将元素从命中测试中移除。

ScrollTrigger 基础

gsap.to(".panel", {
  xPercent: -100,
  ease: "none",
  scrollTrigger: {
    trigger: ".wrap",
    start: "top top",      // 当触发元素的顶部到达视口顶部时
    end: "+=2000",         // 2000px 的滚动距离
    pin: true,             // 在补间播放期间冻结 .wrap
    scrub: 1,              // 将进度与滚动条绑定(1 = 1 秒追赶平滑)
    markers: true,         // 仅开发用的可见标记——生产环境移除
  },
});

关键语义:

  • start/end 接受 "triggerPos viewportPos"(例如 "top center")或 "+=px"。
  • scrub: true 将动画进度与滚动精确锁定;scrub: <number> 添加平滑滞后。
  • toggleActions: "play pause resume reverse" 控制未擦洗触发器的 onEnter/onLeave/onEnterBack/onLeaveBack。
  • 对擦洗的补间使用 ease: "none",以便运动线性跟踪滚动。

平滑滚动(Lenis)+ ScrollTrigger

将 Lenis(或 Locomotive)平滑滚动与 ScrollTrigger 配对时,除非两者在同一个循环上运行,否则会不同步。Lenis 在其自己的 rAF 上平滑滚动,而 ScrollTrigger 在 GSAP 的 ticker 上读取滚动;当它们独立工作时,ScrollTrigger 会采样到过时的位置。解决方法:让 GSAP 的 ticker 驱动 Lenis,并在每次 Lenis 滚动时更新 ScrollTrigger。

import Lenis from "lenis";

const lenis = new Lenis({ duration: 1.2, smoothWheel: true });

lenis.on("scroll", ScrollTrigger.update);          // 1. 每次 Lenis 滚动时更新 ScrollTrigger
gsap.ticker.add((t) => lenis.raf(t * 1000));       // 2. 单一循环:ticker 驱动 Lenis(秒 → 毫秒)
gsap.ticker.lagSmoothing(0);                        // 3. 停止在重帧上 GSAP 的追赶抖动

关键:gsap.ticker 传递秒为单位的时间,lenis.raf() 需要毫秒——乘以 1000。不要还单独运行一个独立的 requestAnimationFrame(raf) 循环用于 Lenis;那会导致双重驱动。

常见错误:

  • 抖动/卡顿——多余的 requestAnimationFrame(raf) 循环与 ticker 竞争,或缺少 lagSmoothing(0)。移除多余循环;将滞后平滑设置为 0。
  • 标记从触发元素上漂移——ScrollTrigger.update 未通过 lenis.on("scroll", …) 订阅。
  • 固定失效——在 Lenis 下,不要设置 scrollerProxy(它滚动文档)。在 Locomotive 下,你必须连接 scrollerProxy + pinType,并在每个触发器上设置 scroller:。
  • 滚动卡住/方向反转——缺少 * 1000 的单位转换,或两个循环顺序错误。

SPA 卸载时的清理:gsap.ticker.remove(update) + lenis.destroy(),否则循环会在每次导航时叠加。根据 prefers-reduced-motion 进行门控(跳过 Lenis,使用原生滚动)。完整的 Lenis + Locomotive 接线、锚点链接路由、data-lenis-prevent、React(useGSAP/useEffect)以及症状→原因表在 references/scrolltrigger-lenis.md 中。

SplitText(文本揭示)

const split = SplitText.create(".headline", { type: "lines, words", linesClass: "line" });
gsap.from(split.lines, { yPercent: 100, opacity: 0, stagger: 0.08, duration: 0.7, ease: "power4.out" });

注意事项:

  • 行遮罩揭示:在行包裹器上设置 overflow: hidden,以便 yPercent: 100 能干净地隐藏。添加 autoSplit: true(GSAP 3.13+)以在字体加载/调整大小时重新拆分。
  • 在重新拆分或卸载前调用 split.revert() 以恢复原始 DOM 并避免节点重复。
  • 始终在 Web 字体加载后(document.fonts.ready.then(...))进行拆分,以防止错误的换行。

Flip(布局过渡)

Flip 记录状态,让 DOM 即时更改,然后动画化视觉差异(FLIP 技术)。适用于网格<->列表、展开卡片和重新父级化。

const state = Flip.getState(".item");   // 1. 在之前捕获
container.classList.toggle("grid");      // 2. 即时更改 DOM/CSS
Flip.from(state, {                        // 3. 动画化增量
  duration: 0.6, ease: "power2.inOut", stagger: 0.05,
  absolute: true,                         // 在移动期间将元素移出文档流(防止重排抖动)
});

缓动快速指南

  • power2/3.out — 入场(快速然后稳定)
  • power2.inOut — 在两个屏幕状态之间移动
  • back.out(1.7) — 过冲/弹出(数字 = 过冲量)
  • elastic.out(1, 0.3) — 有弹性的,谨慎使用
  • none — 擦洗的滚动补间
  • steps(n) — 精灵/步进动画
  • 自定义三次贝塞尔曲线等效:CustomEase.create("x", "M0,0 C0.2,0 0,1 1,1")(CustomEase 免费)

性能与清理

  • 仅动画化 transform(x/y/xPercent/scale/rotation)和 opacity——它们由 GPU 合成,跳过布局/绘制。避免动画化 top/left/width/height。
  • 在重型/固定元素上设置 will-change: transform;完成后移除。
  • 使用 ScrollTrigger.batch() 批量处理许多类似的滚动揭示,而不是为每个元素创建一个触发器。
  • 在视口/内容更改后,调用 ScrollTrigger.refresh()。

SPA / 框架清理是强制性的——孤立的触发器会导致内存泄漏和幽灵固定。使用 gsap.context()(或来自 @gsap/react 的 useGSAP):

useEffect(() => {
  const ctx = gsap.context(() => {
    // 所有 gsap + ScrollTrigger 代码放在这里
  }, rootRef);
  return () => ctx.revert(); // 杀死补间、触发器并恢复内联样式
}, []);

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

对于自包含的动画(主角、揭示、循环、微场景),交付物是一个可以直接在浏览器中打开的 HTML 文件——无需构建步骤,无需框架,无需渲染管线。将交付物与工作的重量相匹配:单个文件是网页动画的正确层级;当一个文件能完成工作时,不要使用打包工具。

输出约定:

  • 一个 .html 文件:从 CDN 获取 GSAP + 插件、你的标记以及一个内联 <script> 中的动画。
  • 所有动画放在一条主时间线(const tl = gsap.timeline())上——一个可以查找的单一播放头。
  • 包含下面的查找挂钩,以便可以冻结任何时刻进行检查。

查找挂钩——冻结精确时刻以便截图。 视频播放器帧固定的 Web 等价物:?t=N 将主时间线查找至 N 秒并暂停,以便截图落在静止的、确定性的帧上。

<script>
  // ... 将你的主时间线构建为 `tl` ...
  const t = new URLSearchParams(location.search).get("t");
  if (t !== null) { tl.pause(); tl.seek(parseFloat(t)); }  // 在 t 秒处冻结
  // 无 ?t → 正常播放
  window.__ready = true;            // 为无头等待准备的就绪信号
  console.log("duration", tl.duration());
</script>

验证循环——渲染 → 冻结 → 截图 → 检查:

  1. 在时间线上的三个时刻打开文件——开始、中间、结束: …/anim.html?t=0、?t=<dur/2>、?t=<dur>。从控制台读取 tl.duration() 获取结束时间。
  2. 截取每个冻结帧的截图。
  3. 检查保真度(是否符合要求?)和伪影(文本被裁剪、元素离开画布、字体加载前出现样式闪烁、接缝处卡顿)。输出应该看起来有意为之且完成度高。

任何无头截图工具都可以——你的代理的浏览器工具,或 Playwright:

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

在完成之前:

  1. 在浏览器中独立打开——无控制台错误,无缺失 CDN。
  2. 所有动画在一条主时间线上;?t=N 正确冻结。
  3. 在开始/中间/结束处截图——符合要求,无伪影。
  4. 尊重 prefers-reduced-motion(时间线简化或跳过)。
  5. 缓动是有意为之的——空间运动上没有意外的 linear。

一个完整的可运行模板(带有已接线的挂钩)在 examples/standalone-template.html 中。

快速参考

目标API
带重叠的序列tl.from(...).from(..., "-=0.3")
滚动时固定scrollTrigger:{ pin:true, end:"+="N" }
擦洗滚动scrollTrigger:{ scrub:1, ease:"none" }
揭示文本行SplitText.create(el,{type:"lines"})
动画化布局更改Flip.getState → 更改 → Flip.from
快速指针跟随gsap.quickTo(el,"x",{...})
杀死所有ScrollTrigger.getAll().forEach(t=>t.kill())

参考文件

  • references/scrolltrigger-cookbook.md — 固定、擦洗、水平滚动、吸附、ScrollTrigger.batch() 揭示、视差、嵌套触发器以及完整代码的 SPA 清理模式。
  • references/scrolltrigger-lenis.md — 完整的 ScrollTrigger + Lenis/Locomotive 平滑滚动同步:规范接线、scrollerProxy、锚点链接、减少运动、React(useGSAP/useEffect)、调试检查清单以及症状→原因表。
  • examples/hero-timeline.js — 一个完整的、可运行的主角入场时间线,包含 SplitText、交错揭示和减少运动处理。
  • examples/standalone-template.html — 交付模板:自包含(CDN GSAP)、一条主时间线、用于截图验证的 ?t=N 查找挂钩以及减少运动处理。

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

相关技能