Configs2026年7月3日·1 分钟阅读

ScrollReveal — Animate Elements as They Scroll Into View

A zero-dependency JavaScript library that creates scroll-based reveal animations for web elements with a simple declarative API.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
ScrollReveal Overview
直接安装命令
npx -y tokrepo@latest install 94a89dbd-7705-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

ScrollReveal is a lightweight JavaScript library that animates elements as they enter the browser viewport during scrolling. It provides a clean declarative API for creating engaging scroll-based reveal effects without any external dependencies or CSS animation frameworks.

What ScrollReveal Does

  • Animates elements when they scroll into the viewport for the first time
  • Supports configurable origin directions (top, bottom, left, right)
  • Offers customizable delay, duration, distance, and easing parameters
  • Handles responsive behavior with container-scoped reveals
  • Provides callback hooks for reveal and reset lifecycle events

Architecture Overview

ScrollReveal works by registering target elements and storing their initial computed styles. It sets up an IntersectionObserver (or a scroll event fallback) to detect when elements enter the viewport. When triggered, it applies CSS transforms and opacity transitions with the configured parameters. The library maintains an internal store of all registered sequences, enabling coordinated reveal ordering across element groups.

Self-Hosting & Configuration

  • Install via npm or include from a CDN with a single script tag
  • Initialize with ScrollReveal({ reset: true }) to re-animate on every scroll
  • Set global defaults by passing a config object to the constructor
  • Use data-sr attributes for inline configuration when preferred
  • Call ScrollReveal().destroy() during SPA route changes to clean up listeners

Key Features

  • Zero external dependencies at under 6 KB gzipped
  • Works with any CSS framework or vanilla HTML
  • Sequenced reveals with interval staggering across groups
  • Mobile-friendly with automatic handling of reduced-motion preferences
  • Supports custom containers for scrollable sub-sections

Comparison with Similar Tools

  • AOS (Animate on Scroll) — uses data attributes and CSS classes; ScrollReveal is fully JS-driven with finer control
  • GSAP ScrollTrigger — more powerful but heavier; ScrollReveal is simpler for basic reveal effects
  • Framer Motion — React-specific; ScrollReveal is framework-agnostic
  • Intersection Observer API — native but low-level; ScrollReveal abstracts it with animation presets

FAQ

Q: Does ScrollReveal work with React or Vue? A: Yes, call ScrollReveal().reveal() inside lifecycle hooks like useEffect or onMounted.

Q: Can I animate elements only once? A: By default elements animate once. Set reset: true to re-animate every time they re-enter the viewport.

Q: Does it support reduced-motion preferences? A: ScrollReveal respects the prefers-reduced-motion media query automatically.

Q: What browsers are supported? A: All modern browsers including Chrome, Firefox, Safari, and Edge.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产