motion-background
This skill should be used when the user asks to "add an animated background", "build a mesh/gradient background", "make an aurora/shader background", "add constellation/particle background", "animated hero background", or "a subtle looping background behind content". Covers CSS mesh gradients, GLSL shader gradients (Three.js), canvas particle constellations, seamless loops, and reduced-motion/performance handling — fully self-contained.
1How It Works & Mechanism
A "batteries-included runnable code" skill: SKILL.md inlines full, runnable implementations for three technologies (CSS gradient keyframes, GLSL fragment shaders via Three.js, and 2D canvas particles). Agents can copy them directly into deliverables—capabilities stem from inlined code rather than external services.
This skill is self-contained: every technique below ships its own runnable code — CSS, GLSL, and canvas — with no external dependencies beyond Three.js where a shader is involved.
Seamless looping is a rigorous technical requirement: CSS relies on matching start and end keyframes; canvas/JS uses loop phase=(t%PERIOD)/PERIOD×2π to drive sin/cos for precise end-of-period rewinding; shaders map noise scrolling to a closed circle in noise space.
Any motion built only from `sin`/`cos` of `phase` (or integer multiples) loops seamlessly.
Performance and accessibility are codified disciplines: devicePixelRatio is capped at 2, O(n²) particle connections switch to spatial hashing above 120 points, prefers-reduced-motion falls back to static frames, and visibilitychange + IntersectionObserver pause rendering when offscreen or hidden.
honor `prefers-reduced-motion`, and pause when offscreen or the tab is hidden.
Delivery contract = single-file HTML: background + sample foreground text + single animation driver + deterministic frame-capture ?t=N freeze harness are fully inlined and ready to open immediately.
A motion background ships as **one `.html` file that opens directly in a browser** — markup, the background, and (for shader/canvas) Three.js or canvas JS from CDN, all inline.
Built-in verification loop: the repo's scripts/ directory provides seek-shot.sh (npx playwright capturing ?t=N frames) and contact-sheet.sh (ffmpeg stitching contact sheets). SKILL.md mandates start/mid/end three-frame captures to inspect fidelity, artifacts, and loop seams.
**Packaged helper** (`scripts/`): `scripts/seek-shot.sh anim.html 0 1.5 3` freezes the `?t=N` harness and screenshots each moment; `scripts/contact-sheet.sh sheet.png frame-*.png` tiles them for one-glance review. See `scripts/README.md`.
Deep-dive implementations live in references/background-recipes.md: multi-blob CSS mesh (blur + screen blending), full aurora with mouse parallax and true seamless loops, grid-optimized constellations with mouse repulsion, closed-path noise scrolling, and a unified lifecycle manager.
references/background-recipes.md — fuller drop-in implementations: a richer multi-blob CSS mesh with blur, the complete Three.js aurora shader with mouse parallax and a true seamless-loop time wrap
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| package | three.js(交付 HTML 运行时依赖;仅 shader 路线,CDN 或 bundler 引入) |
| cli | npx playwright screenshot(验证闭环;seek-shot.sh 内部调用,首次运行自动拉取 Chromium) |
| cli | ffmpeg(contact-sheet.sh 依赖,本地拼图) |
| cli | 仓库 scripts/seek-shot.sh、contact-sheet.sh(POSIX bash 本地工具) |
4Recommended Governance & Evidence
- scripts/: Execute local scripts or commands: SKILL.md instructs the agent to run repository scripts: `scripts/seek-shot.sh anim.html <t...>` (internally runs npx playwright)
- 网络端点: Declare external network access: The skill execution path makes no outbound network requests (screenshots target local file:// HTML); Playwright may download Chromium on first run (seek-shot)
- 本地工作目录: File read/write and artifact output: Writes deliverable bg.html to the working directory (single-file output contract)
5Second-Pass Verification
- [ok] 脚本引用真实性 — SKILL.md 引用的 scripts/seek-shot.sh、contact-sheet.sh、scripts/README.md 在仓库根存在;seek-shot.sh 输出 frame-<t>.png 与 SKILL.md 用法一致。
- [ok] 『no external dependencies beyond Three.js』反查 — SKILL.md/recipes 未出现其他 import/外部 URL 请求(CDN 仅以文字提及 three.js);CSS/canvas 路线零依赖属实。
- [ok] 无凭证/无隐藏网络调用 — token/curl/exec 类扫描零命中;playwright 只访问 file:// 本地页;唯一网络相关=playwright 首跑下载 Chromium(一次性工具安装)与交付页打开时 CDN 加载。
- [discrepancy] 打包粒度风险(scripts/ 不在 skill 目录) — skill 自述依赖的验证脚本位于仓库根 scripts/;若通过 skills.sh 只安装单个 skill 目录(不含 repo 根),scripts/ 引用与 .claude-plugin 打包关系悬空——从源码无法确认各安装方式的粒度,展示层应提示按整 repo/pack 安装。
- [ok] 代码正确性抽查(无缝循环/暂停逻辑) — phase 回卷公式、首尾关键帧一致、uPhase=2π 圆环回原点、IntersectionObserver running 逻辑在 SKILL.md 与 recipes 中一致;未发现逻辑矛盾。
6Verdict & Scenarios
6e74dc92e650a613…