Communitygithub.com

nehakanjamala/personal_website

當使用者要求「建立滾動動畫」、「加入 ScrollTrigger」、「在滾動時固定區塊」、「製作滾輪驅動動畫」、「建立英雄時間軸」、「製作水平滾動區塊」、「分割文字並逐字動畫化」、「使用 GSAP Flip 動畫化版面變更」、「將 ScrollTrigger 與 Lenis 同步」、「Lenis 平滑滾動出現抖動」、「ScrollTrigger 標記偏移」、「ScrollTrigger 固定區塊與 Lenis/Locomotive 衝突」或「設定 GSAP 固定搭配平滑滾動」時使用此技能。涵蓋 GSAP 時間軸、ScrollTrigger、SplitText、Flip 以及 Lenis/Locomotive 平滑滾動同步,適用於程式驅動的網頁動畫。

personal_website 是什麼?

此技能專注於 GSAP (GreenSock Animation Platform) 及其生態系統,為開發者提供全面的網頁動畫解決方案。它涵蓋了核心技術,包括建立序列化時間軸、使用 ScrollTrigger 實現滾動驅動的故事敘述、利用 SplitText 進行文字分割與動畫、以及透過 Flip 處理版面過渡。技能詳細說明了如何正確安裝與註冊 GSAP 及其付費外掛(在 3.12+ 版本後皆為免費),並強調使用時間軸 (timeline) 勝過獨立補間 (tween) 的優勢。 針對常見的實作挑戰,此技能提供了深入的除錯指南,特別是關於 Lenis 或 Locomotive 平滑滾動庫與 ScrollTrigger 的同步問題。它解釋了由於各自獨立的事件循環導致的抖動、標記偏移或固定效果失效的根因,並提供標準的修正寫法,例如從 GSAP 的 ticker 驅動 Lenis。此外,技能還包含 SPA 框架下的清理機制、效能最佳化建議(如僅動畫化 transform 和 opacity)、以及一個完整的驗證流程,確保最終產出的獨立 HTML 檔案能透過 `?t=N` 查詢參數凍結動畫進行截圖檢查,達到高品質的交付標準。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

GSAP 網頁動畫

GSAP(GreenSock Animation Platform)是程式驅動網頁動畫的主力工具:序列化時間軸、滾動驅動的故事敘述、文字揭示以及版面過渡。自 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 與 set 與 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 接受 "觸發元素位置 可視區域位置"(例如 "top center")或 "+=px"。
  • scrub: true 將動畫進度與滾動完全鎖定;scrub: <數值> 則增加平滑延遲。
  • 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。不要另外為 Lenis 執行獨立的 requestAnimationFrame(raf) 循環;這會造成雙重驅動。

常見錯誤:

  • 抖動/卡頓 — 殘留的 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 並避免重複節點。
  • 務必在網頁字體載入完成後(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) — 精靈圖/階梯式動畫
  • 自訂 cubic-bezier 等效: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 檔案:GSAP + 來自 CDN 的外掛、你的標記以及動畫,全部放在一個內嵌的 <script> 中。
  • 所有動畫放在一個主時間軸上(const tl = gsap.timeline())——一個可供你搜尋的單一播放頭。
  • 包含以下搜尋框架,以便任何時刻都能凍結以供檢查。

搜尋框架 — 凍結精確時刻以供截圖。 這是影片播放器影格凍結的網頁版本:?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 → mutate → 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.

相關技能