Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)7.2k · #13396

animation-on-scroll

Skill này làm gì

Skill này hướng dẫn agent thêm hoạt ảnh hiện ra khi cuộn vào một trang web. Nó dành cho chủ trang muốn các phần hiện ra khi đi vào khung nhìn.

Khi nào nên dùng

  • ✓Khi bạn muốn các phần tử hoạt hình hiện ra khi khách cuộn xuống trang.
  • ✓Khi bạn cần một hiệu ứng hiện ra khi cuộn nhanh cho trang dùng Tailwind.
  • ✓Khi bạn muốn mỗi mục trong danh sách xuất hiện với một độ trễ nhỏ.

Liên kết skill

https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/animation-on-scroll/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/MengTo/Skills/blob/main/agent-skills/web-design/animation-on-scroll/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm cho các thẻ tính năng của tôi mờ dần và trượt vào từng cái một khi mọi người cuộn trang.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent thêm một đoạn script nhỏ theo dõi các phần tử đi vào khung nhìn. Khi có phần tử đi vào, nó kích hoạt hoạt ảnh được định nghĩa bằng một keyframe và một lớp Tailwind.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Animation On Scroll Skill

Workflow

  1. Confirm animation style, timing, and whether animations should run once or repeat.
  2. Provide the keyframes + JS observer snippet and the exact Tailwind class to apply.
  3. Offer focused tweaks only (threshold, rootMargin, duration, delay, transform/blur values).

Usage checklist

  • Insert the JS snippet in the <head> after the keyframes.
  • Add the animation class and animate-on-scroll to elements.
  • Ensure your keyframes name matches the Tailwind animation reference.

IntersectionObserver trigger

<script>
  /*
    Sequence animation on scroll when visible. Requires Animation Keyframe. Usage:

    1) Insert this code in the <head> along with the Animation Keyframe code.

    2) Add to Tailwind Classes: [animation:animationIn_0.8s_ease-out_0.1s_both] animate-on-scroll
  */
  (function () {
    // Inject CSS for paused/running states
    const style = document.createElement("style");
    style.textContent = `
      /* Default: paused */
      .animate-on-scroll { animation-play-state: paused !important; }
      /* Activated by 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); // observing twice is a no-op
      });
    };

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

Keyframes

<style>
  /*
    Sequence animation intro. Usage:

    1) Insert this code in the <head>

    2) Add to Tailwind Classes: [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 example

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

Customization knobs

  • Trigger: adjust threshold and rootMargin for earlier/later reveals.
  • Repeat: set once = false to allow replays when re-entering.
  • Motion: tweak translateY and blur in keyframes.
  • Timing: change duration and delay in the Tailwind animation value.

Common pitfalls

  • Forgetting to include the keyframes before the JS snippet.
  • Using a different keyframe name than in the Tailwind animation.
  • Animations not running because the element is already in view before observer init.

Questions to ask when specs are missing

  • Should animations run once or every time the element re-enters?
  • How far before entering the viewport should they start?
  • What motion style (fade, slide, blur, scale) do you want?
Câu hỏi thường gặp

Hoạt ảnh có lặp lại khi tôi cuộn ngược không?

Skill có một thiết lập để chạy một lần hoặc lặp lại, nên bạn có thể chọn.

Code đặt ở đâu?

Script đặt trong phần head của trang sau các keyframe, và lớp được thêm vào mỗi phần tử.

Tôi có thể đổi thời gian không?

Có. Skill có các tùy chỉnh về mức độ phần tử phải hiện trong khung nhìn, cộng với thời lượng, độ trễ và chuyển động.

Chi tiết

Mô tả gốc của tác giả

Create an on-scroll animation trigger using IntersectionObserver with Tailwind-friendly animation classes and keyframes. Use when asked for scroll-reveal, animate-on-scroll, or sequencing element animations when they enter the viewport.

repo: MengTo/Skills

Độ phổ biến

Sao GitHub
7.2k
Vị trí xếp hạng
#13396
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự