Communitygithub.com

MengTo/Skills

使用 IntersectionObserver 建立滾動觸發動畫,搭配 Tailwind 友善的動畫類別與關鍵影格。當使用者要求「滾動顯現」、「進入視窗時動畫」或「序列元素動畫」時使用。

Skills 是什麼?

這是一個「滾動動畫」技巧(技能),專為需要在元素進入視窗時觸發動畫的開發者設計。它提供一個完整的 JavaScript 與 CSS 解決方案,基於 IntersectionObserver API,並與 Tailwind CSS 的動畫類別無縫整合。技巧的核心是一個可自訂的 JS 腳本,它會自動為帶有 `animate-on-scroll` 類別的元素添加 `animate` 類別,從而觸發預先定義的 CSS 關鍵影格動畫。開發者可以調整觸發時機(threshold、rootMargin)、動畫是否重複(once 變數)、以及動畫的視覺效果(位移、模糊、持續時間、延遲)。此技巧支援所有現代瀏覽器,並且特別適合在 Cursor、Claude Code 等 AI 輔助開發環境中使用,因為它提供了可直接複製貼上的程式碼片段。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/MengTo/Skills/tree/HEAD/agent-skills/web-design/animation-on-scroll

在你喜歡的 AI 中提問

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

說明文件

滾動動畫技巧

工作流程

  1. 確認動畫風格、時機,以及動畫應執行一次或重複。
  2. 提供關鍵影格 + JS 觀察器程式碼片段,以及確切的 Tailwind 類別來套用。
  3. 僅提供針對性的調整(threshold、rootMargin、duration、delay、transform/blur 值)。

使用檢查清單

  • 將 JS 程式碼片段插入在 <head> 中的關鍵影格之後。
  • 在元素上加入動畫類別和 animate-on-scroll。
  • 確保你的關鍵影格名稱與 Tailwind 動畫參考一致。

IntersectionObserver 觸發器

<script>
  /*
    在元素可見時依序播放動畫。需要動畫關鍵影格。用法:

    1) 將此程式碼與動畫關鍵影格程式碼一起放入 <head> 中。

    2) 加入 Tailwind 類別:[animation:animationIn_0.8s_ease-out_0.1s_both] animate-on-scroll
  */
  (function () {
    // 注入暫停/執行狀態的 CSS
    const style = document.createElement("style");
    style.textContent = `
      /* 預設:暫停 */
      .animate-on-scroll { animation-play-state: paused !important; }
      /* 由 JS 啟動 */
      .animate-on-scroll.animate { animation-play-state: running !important; }
    `;
    document.head.appendChild(style);

    const once = true;

    if (!window.__inViewIO) {
      window.__inViewIO = new IntersectionObserver((entries) => {
        entries.forEach((entry) => {
          if (entry.isIntersecting) {
            entry.target.classList.add("animate");
            if (once) window.__inViewIO.unobserve(entry.target);
          }
        });
      }, { threshold: 0.2, rootMargin: "0px 0px -10% 0px" });
    }

    window.initInViewAnimations = function (selector = ".animate-on-scroll") {
      document.querySelectorAll(selector).forEach((el) => {
        window.__inViewIO.observe(el); // 重複觀察無效
      });
    };

    document.addEventListener("DOMContentLoaded", () => initInViewAnimations());
  })();
</script>

關鍵影格

<style>
  /*
    序列動畫引入。用法:

    1) 將此程式碼放入 <head> 中

    2) 加入 Tailwind 類別:[animation:animationIn_0.8s_ease-out_0.1s_both]
  */
  @keyframes animationIn {
    0% {
      opacity: 0;
      transform: translateY(30px);
      filter: blur(8px);
    }

    100% {
      opacity: 1;
      transform: translateY(0);
      filter: blur(0px);
    }
  }
</style>

Tailwind 範例

<div class="animate-on-scroll [animation:animationIn_0.8s_ease-out_0.1s_both]">
  ...
</div>

自訂旋鈕

  • 觸發:調整 threshold 和 rootMargin 以控制早/晚顯現。
  • 重複:設定 once = false 以允許重新進入時重播。
  • 動態:在關鍵影格中調整 translateY 和 blur。
  • 時機:在 Tailwind 動畫值中變更持續時間和延遲。

常見陷阱

  • 忘記在 JS 程式碼片段之前包含關鍵影格。
  • 使用與 Tailwind 動畫中不同的關鍵影格名稱。
  • 動畫無法執行,因為元素在觀察器初始化前已在視窗內。

規格遺漏時應提出的問題

  • 動畫應執行一次還是每次元素重新進入時執行?
  • 應在進入視窗多遠前開始觸發?
  • 想要哪種動態風格(淡入、滑入、模糊、縮放)?

Individual skills in this repo

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

MengTo/Skills

Create polished 60 fps 4:3 4K browser screen-recording style videos from Codex in-app browser captures, with browser-only crop, natural macOS cursor styling, deliberate click choreography, zoom-follow framing, ffprobe/thumbnail verification, and optional native recording compatibility checks. Use when the user asks to record or re-record browser actions, show cursor clicks and zooms, make Dribbble/UI inspiration or product demo recordings, or asks whether Codex, Playwright, or an MCP can produce a natural browser demo video.

MengTo/Skills

Generate ElevenLabs text-to-speech audio from scripts or inline text using local voice profiles. Use when the user asks for ElevenLabs, text-to-speech, TTS, narration, voiceover, speech audio, or voice generation; load voice names, voice ids, emails, owners, and account-specific defaults only from local config outside the skill.

MengTo/Skills

Profile, audit, and optimize frontend page performance with emphasis on animation work, memory-leak risks, long-session slowdowns, CSS animations, canvas/WebGL requestAnimationFrame loops, marquees, skeletons, GSAP/Three/Matter effects, timers, listeners, and observers. Use when the user asks to make animations performant, pause offscreen animations, look for memory leaks, profile pages that slow the computer over time, fix janky scrolling, reduce CPU/GPU use, or repeat the "only play in view" optimization on React/Vite/Next/frontend pages using Codex Browser.

MengTo/Skills

Turn a reference video into a super detailed recreation or inspiration prompt. Use when the user provides, mentions, uploads, links, or points to a video and asks to analyze the design, UI, animations, transitions, scroll interactions, typography, colors, assets, WebGL/Three.js, storytelling, section-by-section behavior, or to create a prompt/article that recreates the page, app, interaction, or motion system.

MengTo/Skills

Use when designing or implementing product-grade web motion like Stripe, Linear, Apple, and Vercel. Covers motion principles, easing/duration defaults, choreography patterns, scroll/hover interactions, performance, accessibility (reduced motion), and implementation guidance.

MengTo/Skills

Create premium cinematic web motion systems with GSAP, ScrollTrigger, and Lenis. Use for luxury editorial websites, creative studio portfolios, Awwwards-style interactions, smooth scroll reveals, staggered text, parallax, pinned sections, magnetic hover states, custom cursors, and mouse-reactive layered movement.

MengTo/Skills

Create cinematic scroll-driven landing pages with Lenis smooth scrolling, GSAP ScrollTrigger, scroll-linked progression, staggered text reveals, sticky card stacks, parallax backgrounds, scroll-scrubbed transitions, footer reveals, and immersive preloaders. Use when analyzing or building premium editorial scroll experiences, sticky project stacks, kinetic typography, or section-by-section storytelling.

MengTo/Skills

Use when designing or rewriting a high-converting SaaS pricing page (structure, plan design, copywriting, SEO/AEO, FAQs, layout patterns, experiments). Includes checklists, templates, and common pitfalls.

MengTo/Skills

Use when creating or refining WebGL-heavy landing pages and you need to steer toward a specific visual outcome (premium, technical, playful, cinematic) while balancing conversion clarity, performance, and implementation complexity.

相關技能