Communitygithub.com

Geruyang/agent-skills-library

GSAP 動畫參考,適用於 HyperFrames。涵蓋 gsap.to()、from()、fromTo()、easing、stagger、defaults、時間軸(gsap.timeline()、位置參數、標籤、嵌套、播放控制)以及效能最佳化(transform、will-change、quickTo)。在撰寫 HyperFrames 組合中的 GSAP 動畫時使用。

agent-skills-library 是什麼?

此技能提供一個全面的 GSAP(GreenSock Animation Platform)動畫參考庫,專為 HyperFrames 環境設計。它詳細說明核心補間方法,包括 `gsap.to()`、`gsap.from()`、`gsap.fromTo()` 以及 `gsap.set()`,並強調使用駝峰式命名與轉換別名來獲得最佳效能。技能文件深入探討進階主題,例如函數式值、內建緩動函數、全域預設值、補間控制以及 `gsap.matchMedia()` 以實現響應式和無障礙動畫。它還全面介紹了時間軸的建立、位置參數、標籤、嵌套和播放控制,讓開發者能夠編排複雜的序列。在效能方面,技能提倡優先動畫化 transform 和 opacity 屬性、使用 `will-change`、針對頻繁更新採用 `gsap.quickTo()`、利用 stagger 取代手動延遲,以及妥善清理補間,確保 HyperFrames 組合中的動畫順暢且高效。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Geruyang/agent-skills-library/tree/HEAD/original-skills/x-openai-gsap-646176d

在你喜歡的 AI 中提問

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

說明文件

GSAP

核心補間方法

  • gsap.to(targets, vars) — 從當前狀態動畫到 vars。最常用。
  • gsap.from(targets, vars) — 從 vars 動畫到當前狀態(入場動畫)。
  • gsap.fromTo(targets, fromVars, toVars) — 明確指定起始與結束狀態。
  • gsap.set(targets, vars) — 立即套用(持續時間 0)。

務必使用駝峰式命名的屬性名稱(例如 backgroundColor、rotationX)。

常用變數

  • duration — 秒(預設 0.5)。
  • delay — 開始前的延遲秒數。
  • ease — "power1.out"(預設)、"power3.inOut"、"back.out(1.7)"、"elastic.out(1, 0.3)"、"none"。
  • stagger — 數字 0.1 或物件:{ amount: 0.3, from: "center" }、{ each: 0.1, from: "random" }。
  • overwrite — false(預設)、true 或 "auto"。
  • repeat — 數字或 -1 表示無限循環。yoyo — 與 repeat 搭配使用,交替方向。
  • onComplete、onStart、onUpdate — 回呼函式。
  • immediateRender — 在 from()/fromTo() 中預設為 true。若後續有針對相同屬性與元素的補間,請設為 false 以避免覆蓋。

變形與 CSS

優先使用 GSAP 的變形別名而非原始 transform 字串:

GSAP 屬性等效屬性
x、y、ztranslateX/Y/Z(px)
xPercent、yPercenttranslateX/Y(%)
scale、scaleX、scaleYscale
rotationrotate(度)
rotationX、rotationY3D rotate
skewX、skewYskew
transformOrigintransform-origin
  • autoAlpha — 優先於 opacity。值為 0 時,同時設定 visibility: hidden。
  • CSS 變數 — "--hue": 180。
  • svgOrigin(僅 SVG)— 全域 SVG 座標空間原點。請勿與 transformOrigin 同時使用。
  • 方向性旋轉 — "360_cw"、"-170_short"、"90_ccw"。
  • clearProps — "all" 或逗號分隔;在補間完成時移除內聯樣式。
  • 相對值 — "+=20"、"-=10"、"*=2"。

函數式值

gsap.to(".item", {
  x: (i, target, targets) => i * 50,
  stagger: 0.1,
});

緩動函數

內建緩動函數:power1–power4、back、bounce、circ、elastic、expo、sine。每個都有 .in、.out、.inOut。

預設值

gsap.defaults({ duration: 0.6, ease: "power2.out" });

控制補間

const tween = gsap.to(".box", { x: 100 });
tween.pause();
tween.play();
tween.reverse();
tween.kill();
tween.progress(0.5);
tween.time(0.2);

gsap.matchMedia()(響應式 + 無障礙)

僅在符合媒體查詢時執行設定;不符合時自動還原。

let mm = gsap.matchMedia();
mm.add(
  {
    isDesktop: "(min-width: 800px)",
    reduceMotion: "(prefers-reduced-motion: reduce)",
  },
  (context) => {
    const { isDesktop, reduceMotion } = context.conditions;
    gsap.to(".box", {
      rotation: isDesktop ? 360 : 180,
      duration: reduceMotion ? 0 : 2,
    });
  },
);

時間軸

建立時間軸

const tl = gsap.timeline({ defaults: { duration: 0.5, ease: "power2.out" } });
tl.to(".a", { x: 100 }).to(".b", { y: 50 }).to(".c", { opacity: 0 });

位置參數

第三個參數控制放置位置:

  • 絕對位置: 1 — 在 1 秒處
  • 相對位置: "+=0.5" — 在結束之後;"-=0.2" — 在結束之前
  • 標籤: "intro"、"intro+=0.3"
  • 對齊: "<" — 與前一個同時開始;">" — 在前一個結束後開始;"<0.2" — 在前一個開始後 0.2 秒
tl.to(".a", { x: 100 }, 0);
tl.to(".b", { y: 50 }, "<"); // 與 .a 同時開始
tl.to(".c", { opacity: 0 }, "<0.2"); // 在 .b 開始後 0.2 秒

標籤

tl.addLabel("intro", 0);
tl.to(".a", { x: 100 }, "intro");
tl.addLabel("outro", "+=0.5");
tl.play("outro");
tl.tweenFromTo("intro", "outro");

時間軸選項

  • paused: true — 建立時暫停;呼叫 .play() 來開始。
  • repeat、yoyo — 套用至整個時間軸。
  • defaults — 合併到每個子補間的變數。

嵌套時間軸

const master = gsap.timeline();
const child = gsap.timeline();
child.to(".a", { x: 100 }).to(".b", { y: 50 });
master.add(child, 0);

播放控制

tl.play()、tl.pause()、tl.reverse()、tl.restart()、tl.time(2)、tl.progress(0.5)、tl.kill()。


效能

優先使用 Transform 與 Opacity

動畫化 x、y、scale、rotation、opacity 會停留在合成器層。當 transform 可以達到相同效果時,避免使用 width、height、top、left。

will-change

will-change: transform;

僅在實際會動畫化的元素上使用。

gsap.quickTo() 用於頻繁更新

let xTo = gsap.quickTo("#id", "x", { duration: 0.4, ease: "power3" }),
  yTo = gsap.quickTo("#id", "y", { duration: 0.4, ease: "power3" });
container.addEventListener("mousemove", (e) => {
  xTo(e.pageX);
  yTo(e.pageY);
});

Stagger 優於多個補間

使用 stagger 代替多個帶手動延遲的補間。

清理

暫停或移除畫面外的動畫。


參考資料(按需載入)

  • references/effects.md — 即用型效果:打字機文字、音訊視覺化工具。當需要 HyperFrames 的現成效果模式時閱讀。

最佳實踐

  • 使用駝峰式屬性名稱;優先使用 transform 別名和 autoAlpha。
  • 優先使用時間軸而非帶有 delay 的鏈式調用;使用位置參數。
  • 使用 addLabel() 添加標籤以實現可讀性強的序列編排。
  • 將預設值傳遞給時間軸建構函式。
  • 在需要控制播放時,儲存補間/時間軸的回傳值。

禁止事項

  • 當 transform 足夠時,不要動畫化佈局屬性(width/height/top/left)。
  • 不要在相同的 SVG 元素上同時使用 svgOrigin 和 transformOrigin。
  • 當時間軸可以編排序列時,不要使用 delay 來鏈式調用動畫。
  • 不要在 DOM 存在之前建立補間。
  • 不要略過清理 — 不再需要時務必移除補間。

Individual skills in this repo

This repo contains 12 individual skills — each has its own dedicated page.

Geruyang/agent-skills-library

Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.

Geruyang/agent-skills-library

Set up Tailwind CSS v4 in Expo with react-native-css and NativeWind v5 for universal styling

Geruyang/agent-skills-library

Use for new frontend applications, dashboards, games, creative websites, hero sections, and visually driven UI from scratch, or when the user explicitly asks for a redesign/restyle/modernization. Builds from clean, airy, high-taste, readable image-generated concept design with section-specific references, faithful implementation, and browser testing.

Geruyang/agent-skills-library

Use when testing, debugging, or making targeted improvements to rendered frontend apps through the Build Web Apps or web dev plugin: local dev servers, UI regressions, interaction bugs, console errors, responsive layout, and visual QA. Check whether the Browser plugin is available and use it first when it is; otherwise use regular Playwright with the recorded reason.

Geruyang/agent-skills-library

Design UI surfaces for browser games. Use when the user asks for HUDs, menus, overlays, responsive layouts, or visual direction that must protect the playfield.

Geruyang/agent-skills-library

Guide for building, configuring, and deploying microfrontends on Vercel. Use this skill when the user mentions microfrontends, multi-zones, splitting an app across teams, independent deployments, cross-app routing, incremental migration, composing multiple frontends under one domain, microfrontends.json, @vercel/microfrontends, the microfrontends local proxy, or path-based routing between Vercel projects. Also use when the user asks about shared layouts across projects, navigation between microfrontends, fallback environments, asset prefixes, or feature flag controlled routing.

Geruyang/agent-skills-library

Next.js App Router expert guidance. Use when building, debugging, or architecting Next.js applications — routing, Server Components, Server Actions, Cache Components, layouts, middleware/proxy, data fetching, rendering strategies, and deployment on Vercel.

Geruyang/agent-skills-library

Use when sizing Public Equity Investing positions, finding equity hedges, or building an integrated position-and-hedge risk plan from a listed-equity thesis. Do not use for thesis construction, standalone event underwriting, trade execution, personal investment advice, or credit-instrument risk.

Geruyang/agent-skills-library

Integrate data visualizations into React and Next.js applications. Use when the user needs chart components, UML-like or architecture diagram components, React integration patterns, Next.js client or server boundaries, hydration-safe rendering, lazy loading, framework-aware performance, scroll-driven visual stories, or export guidance.

Geruyang/agent-skills-library

shadcn/ui expert guidance — CLI, component installation, composition patterns, custom registries, theming, Tailwind CSS integration, and high-quality interface design. Use when initializing shadcn, adding components, composing product UI, building custom registries, configuring themes, or troubleshooting component issues.

Geruyang/agent-skills-library

v0 by Vercel expert guidance. Use when discussing AI code generation, generating UI components from prompts, v0 CLI usage, v0 SDK/API integration, or integrating v0 into development workflows with GitHub and Vercel deployment.

Geruyang/agent-skills-library

Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".

相關技能