Guide

Getting started

Install @samline/reveal with a package manager or a script tag, load the stylesheet and reveal your first elements.

Install @samline/reveal, then follow the Package / ESM or the HTML / CDN path to the first reveal. Both use the same API.

Requirements

  • Any modern browser. Without IntersectionObserver, content simply stays visible.
  • Scrub mode needs scroll-driven animations (animation-timeline: view()); elsewhere scrub elements stay visible.
  • On the server, reveal and autoReveal return controllers whose methods do nothing.
  • No runtime dependencies.

Install

npm

Terminal
npm install @samline/reveal

pnpm

Terminal
pnpm add @samline/reveal

yarn

Terminal
yarn add @samline/reveal

bun

Terminal
bun add @samline/reveal

HTML / CDN

Terminal
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/style.css">
<script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js" defer></script>

Package / ESM

import '@samline/reveal/style.css'
import { autoReveal } from '@samline/reveal'

autoReveal()
<section data-reveal>Slides up</section>
<ul data-reveal-stagger="80">
  <li data-reveal="fade">One</li>
  <li data-reveal="fade">Two</li>
</ul>

autoReveal() reveals every [data-reveal] in the page, including elements added later. To reveal specific elements, call reveal(target, options); both return a controller with show, hide, update, refresh, finished and destroy. Available as ESM and CommonJS (require('@samline/reveal')); the stylesheet is @samline/reveal/style.css (or dist/style.css).

HTML / CDN

For Shopify, WordPress or plain HTML pages without a build step, load the stylesheet and the browser bundle. It reveals every [data-reveal] as soon as the DOM is ready. Pin the version in production.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/style.css" />
<script
  src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"
  defer
></script>

To pass options, add data-manual to the script tag and start it yourself, or call Reveal.auto() from a script that runs before the DOM is ready (a deferred or inline script after the bundle):

<script
  src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"
  data-manual
  defer
></script>
<script type="module">
  Reveal.auto({ stagger: 60, rootMargin: '0px 0px -10% 0px' })
</script>

Working starter files

A complete page you can save and open: the live preview runs the real package, and its files load the published browser bundle.

CascadeLive preview

Scroll the box: the items enter one after another. data-reveal-stagger on the container delays each item that enters with the others, in document order. Items already in view on load are never hidden.

Scroll down

  • Fast
  • Typed
  • Tiny
  • Accessible
  • Printable
  • Framework-free
Explore the code

HTML / CDN

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Cascade a grid as it scrolls in</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/style.css"
    />
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <ul class="grid" data-reveal-stagger="90">
          <li data-reveal>Fast</li>
          <li data-reveal>Typed</li>
          <li data-reveal>Tiny</li>
          <li data-reveal>Accessible</li>
          <li data-reveal>Printable</li>
          <li data-reveal>Framework-free</li>
        </ul>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script src="./main.js" defer></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.75rem;
}
.grid li {
  padding: 1.25rem;
  background: #f3f3f3;
}

JavaScript

main.js
// The box scrolls instead of the page, so pass it as the root.
// Called before the DOM is ready, this replaces the automatic start.
Reveal.auto({ root: document.querySelector('#page') })

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Cascade a grid as it scrolls in</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/style.css"
    />
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .grid {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
        gap: 0.75rem;
      }
      .grid li {
        padding: 1.25rem;
        background: #f3f3f3;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <ul class="grid" data-reveal-stagger="90">
          <li data-reveal>Fast</li>
          <li data-reveal>Typed</li>
          <li data-reveal>Tiny</li>
          <li data-reveal>Accessible</li>
          <li data-reveal>Printable</li>
          <li data-reveal>Framework-free</li>
        </ul>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      // The box scrolls instead of the page, so pass it as the root.
      // Called before the DOM is ready, this replaces the automatic start.
      Reveal.auto({ root: document.querySelector('#page') })
    </script>
  </body>
</html>

Package / ESM

HTML

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Cascade a grid as it scrolls in</title>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <ul class="grid" data-reveal-stagger="90">
          <li data-reveal>Fast</li>
          <li data-reveal>Typed</li>
          <li data-reveal>Tiny</li>
          <li data-reveal>Accessible</li>
          <li data-reveal>Printable</li>
          <li data-reveal>Framework-free</li>
        </ul>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.75rem;
}
.grid li {
  padding: 1.25rem;
  background: #f3f3f3;
}

JavaScript

main.js
import { autoReveal } from '@samline/reveal'
import '@samline/reveal/style.css'

// The box scrolls instead of the page, so pass it as the root.
autoReveal({ root: document.querySelector('#page') })

Complete file

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Cascade a grid as it scrolls in</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .grid {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
        gap: 0.75rem;
      }
      .grid li {
        padding: 1.25rem;
        background: #f3f3f3;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <ul class="grid" data-reveal-stagger="90">
          <li data-reveal>Fast</li>
          <li data-reveal>Typed</li>
          <li data-reveal>Tiny</li>
          <li data-reveal>Accessible</li>
          <li data-reveal>Printable</li>
          <li data-reveal>Framework-free</li>
        </ul>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      // The box scrolls instead of the page, so pass it as the root.
      autoReveal({ root: document.querySelector('#page') })
    </script>
  </body>
</html>

Next steps