Communitygithub.com

滚动动画技能

使用 IntersectionObserver 创建滚动触发动画,配合 Tailwind 动画类和关键帧。适用于滚动显示、进入视口动画或元素顺序动画的需求。

滚动动画技能 是什么?

该技能通过 IntersectionObserver 实现基于视口可见性的动画触发机制,专为 Tailwind CSS 用户设计。开发者只需在 HTML 元素上添加 `animate-on-scroll` 类和一个 Tailwind 动画类(如 `[animation:animationIn_0.8s_ease-out_0.1s_both]`),即可在元素进入视口时自动运行动画。技能提供了完整的 JavaScript 监听器代码和 CSS 关键帧示例,支持自定义阈值(threshold)、根边距(rootMargin)、动画时长、延迟和变换效果(如平移、模糊)。默认动画为一次性播放,但可通过设置 `once = false` 实现重复触发。常见陷阱包括关键帧与动画名称不匹配、元素已在视口中导致动画不触发等。该技能支持所有基于 Tailwind 的项目,并可与 Cursor、Codex 等 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. 仅进行有针对性的调整(阈值、根边距、时长、延迟、变换/模糊值)。

使用检查清单

  • 将 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.

相关技能