Skip to content
@samline/revealv2.0.0
AboutInstallRecipesFAQExamplesDocs

@samline/reveal

Explore Reveal

A starting point, a working example, and the details when you need them.

  • 01AboutUnderstand the problem and the approach.
  • 02InstallChoose your setup and follow the first steps.
  • 03RecipesUseful patterns and integration context.
  • 04FAQFind the practical details.
  • 05ExamplesTry a preview and explore its code.
  • 06DocsRead guides and the complete reference.

Around the project

  • GitHub(opens in a new tab)
  • npm(opens in a new tab)

v2.0.0·MIT

GitHub(opens in a new tab)Get started
Examples

Reveal examples.

Live previews of distinct scenarios, each with independently copyable files. The same examples appear in the documentation.

Try the exampleInstallation guide

Each preview runs the real package. The copied files load the published browser bundle, so they run as they are.

Choose an example

CascadeEffectsComposeEventsControlsPresetsConditionsStaggerSplit textScrub
01 / Cascade

Cascade a grid as it scrolls in

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
Try it
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>
02 / Effects

Every effect, replayed on each entry

EffectsLive preview

Scroll the box down and back up to see each effect play. The value of data-reveal picks the effect. data-reveal-repeat hides an element again when it leaves, so it plays every time it comes back.

Scroll down, then back up

up
down
left
right
fade
zoom
rotate
wipe-up
wipe-down
wipe-left
wipe-right
blur, 900ms
Try it
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>Every effect, replayed on each entry</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, then back up</p>
        <div class="item" data-reveal="up" data-reveal-repeat>up</div>
        <div class="item" data-reveal="down" data-reveal-repeat>down</div>
        <div class="item" data-reveal="left" data-reveal-repeat>left</div>
        <div class="item" data-reveal="right" data-reveal-repeat>right</div>
        <div class="item" data-reveal="fade" data-reveal-repeat>fade</div>
        <div class="item" data-reveal="zoom" data-reveal-repeat>zoom</div>
        <div class="item" data-reveal="blur" data-reveal-repeat data-reveal-duration="900">
          blur, 900ms
        </div>
        <div class="item" data-reveal="rotate" data-reveal-repeat>rotate</div>
        <div class="item" data-reveal="wipe-up" data-reveal-repeat>wipe-up</div>
        <div class="item" data-reveal="wipe-down" data-reveal-repeat>wipe-down</div>
        <div class="item" data-reveal="wipe-left" data-reveal-repeat>wipe-left</div>
        <div class="item" data-reveal="wipe-right" data-reveal-repeat>wipe-right</div>
      </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;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
  --reveal-distance: 1.5rem;
}

JavaScript

main.js
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>Every effect, replayed on each entry</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;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
        --reveal-distance: 1.5rem;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <div class="item" data-reveal="up" data-reveal-repeat>up</div>
        <div class="item" data-reveal="down" data-reveal-repeat>down</div>
        <div class="item" data-reveal="left" data-reveal-repeat>left</div>
        <div class="item" data-reveal="right" data-reveal-repeat>right</div>
        <div class="item" data-reveal="fade" data-reveal-repeat>fade</div>
        <div class="item" data-reveal="zoom" data-reveal-repeat>zoom</div>
        <div class="item" data-reveal="blur" data-reveal-repeat data-reveal-duration="900">
          blur, 900ms
        </div>
        <div class="item" data-reveal="rotate" data-reveal-repeat>rotate</div>
        <div class="item" data-reveal="wipe-up" data-reveal-repeat>wipe-up</div>
        <div class="item" data-reveal="wipe-down" data-reveal-repeat>wipe-down</div>
        <div class="item" data-reveal="wipe-left" data-reveal-repeat>wipe-left</div>
        <div class="item" data-reveal="wipe-right" data-reveal-repeat>wipe-right</div>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      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>Every effect, replayed on each entry</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, then back up</p>
        <div class="item" data-reveal="up" data-reveal-repeat>up</div>
        <div class="item" data-reveal="down" data-reveal-repeat>down</div>
        <div class="item" data-reveal="left" data-reveal-repeat>left</div>
        <div class="item" data-reveal="right" data-reveal-repeat>right</div>
        <div class="item" data-reveal="fade" data-reveal-repeat>fade</div>
        <div class="item" data-reveal="zoom" data-reveal-repeat>zoom</div>
        <div class="item" data-reveal="blur" data-reveal-repeat data-reveal-duration="900">
          blur, 900ms
        </div>
        <div class="item" data-reveal="rotate" data-reveal-repeat>rotate</div>
        <div class="item" data-reveal="wipe-up" data-reveal-repeat>wipe-up</div>
        <div class="item" data-reveal="wipe-down" data-reveal-repeat>wipe-down</div>
        <div class="item" data-reveal="wipe-left" data-reveal-repeat>wipe-left</div>
        <div class="item" data-reveal="wipe-right" data-reveal-repeat>wipe-right</div>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
  --reveal-distance: 1.5rem;
}

JavaScript

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

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>Every effect, replayed on each entry</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
        --reveal-distance: 1.5rem;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <div class="item" data-reveal="up" data-reveal-repeat>up</div>
        <div class="item" data-reveal="down" data-reveal-repeat>down</div>
        <div class="item" data-reveal="left" data-reveal-repeat>left</div>
        <div class="item" data-reveal="right" data-reveal-repeat>right</div>
        <div class="item" data-reveal="fade" data-reveal-repeat>fade</div>
        <div class="item" data-reveal="zoom" data-reveal-repeat>zoom</div>
        <div class="item" data-reveal="blur" data-reveal-repeat data-reveal-duration="900">
          blur, 900ms
        </div>
        <div class="item" data-reveal="rotate" data-reveal-repeat>rotate</div>
        <div class="item" data-reveal="wipe-up" data-reveal-repeat>wipe-up</div>
        <div class="item" data-reveal="wipe-down" data-reveal-repeat>wipe-down</div>
        <div class="item" data-reveal="wipe-left" data-reveal-repeat>wipe-left</div>
        <div class="item" data-reveal="wipe-right" data-reveal-repeat>wipe-right</div>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      autoReveal({ root: document.querySelector('#page') })
    </script>
  </body>
</html>
03 / Compose

Combine effects and pick an easing

ComposeLive preview

Scroll the box down and back up to see the combinations. Separate effects with spaces to combine them: data-reveal="up blur". data-reveal-easing picks a preset (smooth, snappy, spring, bounce). Use 800 to 1000 ms for spring and bounce.

Scroll down, then back up

up blur
zoom fade
left rotate
wipe-up fade
smooth
snappy
spring
bounce
Try it
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>Combine effects and pick an easing</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, then back up</p>
        <div class="row">
          <div class="item" data-reveal="up blur" data-reveal-repeat>up blur</div>
          <div class="item" data-reveal="zoom fade" data-reveal-repeat>zoom fade</div>
          <div class="item" data-reveal="left rotate" data-reveal-repeat>left rotate</div>
          <div class="item" data-reveal="wipe-up fade" data-reveal-repeat>wipe-up fade</div>
        </div>
        <div class="row">
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="smooth"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            smooth
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="snappy"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            snappy
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="spring"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            spring
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="bounce"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            bounce
          </div>
        </div>
      </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;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.75rem;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
  --reveal-distance: 1.5rem;
}

JavaScript

main.js
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>Combine effects and pick an easing</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;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .row {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
        gap: 0.75rem;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
        --reveal-distance: 1.5rem;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <div class="row">
          <div class="item" data-reveal="up blur" data-reveal-repeat>up blur</div>
          <div class="item" data-reveal="zoom fade" data-reveal-repeat>zoom fade</div>
          <div class="item" data-reveal="left rotate" data-reveal-repeat>left rotate</div>
          <div class="item" data-reveal="wipe-up fade" data-reveal-repeat>wipe-up fade</div>
        </div>
        <div class="row">
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="smooth"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            smooth
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="snappy"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            snappy
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="spring"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            spring
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="bounce"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            bounce
          </div>
        </div>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      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>Combine effects and pick an easing</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, then back up</p>
        <div class="row">
          <div class="item" data-reveal="up blur" data-reveal-repeat>up blur</div>
          <div class="item" data-reveal="zoom fade" data-reveal-repeat>zoom fade</div>
          <div class="item" data-reveal="left rotate" data-reveal-repeat>left rotate</div>
          <div class="item" data-reveal="wipe-up fade" data-reveal-repeat>wipe-up fade</div>
        </div>
        <div class="row">
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="smooth"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            smooth
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="snappy"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            snappy
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="spring"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            spring
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="bounce"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            bounce
          </div>
        </div>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

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

JavaScript

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

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>Combine effects and pick an easing</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .row {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
        gap: 0.75rem;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
        --reveal-distance: 1.5rem;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <div class="row">
          <div class="item" data-reveal="up blur" data-reveal-repeat>up blur</div>
          <div class="item" data-reveal="zoom fade" data-reveal-repeat>zoom fade</div>
          <div class="item" data-reveal="left rotate" data-reveal-repeat>left rotate</div>
          <div class="item" data-reveal="wipe-up fade" data-reveal-repeat>wipe-up fade</div>
        </div>
        <div class="row">
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="smooth"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            smooth
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="snappy"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            snappy
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="spring"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            spring
          </div>
          <div
            class="item"
            data-reveal="up"
            data-reveal-easing="bounce"
            data-reveal-repeat
            data-reveal-duration="900"
          >
            bounce
          </div>
        </div>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      autoReveal({ root: document.querySelector('#page') })
    </script>
  </body>
</html>
04 / Events

Count reveals with lifecycle events

EventsLive preview

Scroll the box and watch the count above it. reveal:show, reveal:end and reveal:hide bubble from the element, so one listener on document sees them all. detail.animated is false for elements shown without a transition.

Revealed 0 of 6

Scroll down

One
Two
Three
Four
Five
Six
Try it
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>Count reveals with lifecycle events</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>
      <p id="status" role="status">Revealed 0 of 6</p>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
        <div class="item" data-reveal>Five</div>
        <div class="item" data-reveal>Six</div>
      </div>
      <button id="reset" type="button">
        <svg
          width="16"
          height="16"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
        >
          <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
          <path d="M3 3v5h5" />
        </svg>
        Reset
      </button>
    </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;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}
#reset {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

JavaScript

main.js
const page = document.querySelector('#page')
const status = document.querySelector('#status')
const total = page.querySelectorAll('[data-reveal]').length
let revealed = 0

const render = () => {
  status.textContent = 'Revealed ' + revealed + ' of ' + total
}

// Events bubble, so one listener on document sees every element.
document.addEventListener('reveal:end', () => {
  revealed += 1
  render()
})

document.querySelector('#reset').addEventListener('click', () => {
  revealed = 0
  render()
  page.scrollTop = 0
  Reveal.auto({ root: page })
})

Reveal.auto({ root: 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>Count reveals with lifecycle events</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;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
      #reset {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        margin-top: 0.75rem;
      }
    </style>
  </head>
  <body>
    <main>
      <p id="status" role="status">Revealed 0 of 6</p>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
        <div class="item" data-reveal>Five</div>
        <div class="item" data-reveal>Six</div>
      </div>
      <button id="reset" type="button">
        <svg
          width="16"
          height="16"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
        >
          <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
          <path d="M3 3v5h5" />
        </svg>
        Reset
      </button>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      const page = document.querySelector('#page')
      const status = document.querySelector('#status')
      const total = page.querySelectorAll('[data-reveal]').length
      let revealed = 0

      const render = () => {
        status.textContent = 'Revealed ' + revealed + ' of ' + total
      }

      // Events bubble, so one listener on document sees every element.
      document.addEventListener('reveal:end', () => {
        revealed += 1
        render()
      })

      document.querySelector('#reset').addEventListener('click', () => {
        revealed = 0
        render()
        page.scrollTop = 0
        Reveal.auto({ root: page })
      })

      Reveal.auto({ root: 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>Count reveals with lifecycle events</title>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <main>
      <p id="status" role="status">Revealed 0 of 6</p>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
        <div class="item" data-reveal>Five</div>
        <div class="item" data-reveal>Six</div>
      </div>
      <button id="reset" type="button">
        <svg
          width="16"
          height="16"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
        >
          <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
          <path d="M3 3v5h5" />
        </svg>
        Reset
      </button>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}
#reset {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

JavaScript

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

const page = document.querySelector('#page')
const status = document.querySelector('#status')
const total = page.querySelectorAll('[data-reveal]').length
let revealed = 0
let controller = autoReveal({ root: page })

const render = () => {
  status.textContent = 'Revealed ' + revealed + ' of ' + total
}

// Events bubble, so one listener on document sees every element.
document.addEventListener('reveal:end', () => {
  revealed += 1
  render()
})

document.querySelector('#reset').addEventListener('click', () => {
  revealed = 0
  render()
  page.scrollTop = 0
  controller.destroy()
  controller = autoReveal({ root: 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>Count reveals with lifecycle events</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
      #reset {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        margin-top: 0.75rem;
      }
    </style>
  </head>
  <body>
    <main>
      <p id="status" role="status">Revealed 0 of 6</p>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
        <div class="item" data-reveal>Five</div>
        <div class="item" data-reveal>Six</div>
      </div>
      <button id="reset" type="button">
        <svg
          width="16"
          height="16"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
        >
          <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
          <path d="M3 3v5h5" />
        </svg>
        Reset
      </button>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      const page = document.querySelector('#page')
      const status = document.querySelector('#status')
      const total = page.querySelectorAll('[data-reveal]').length
      let revealed = 0
      let controller = autoReveal({ root: page })

      const render = () => {
        status.textContent = 'Revealed ' + revealed + ' of ' + total
      }

      // Events bubble, so one listener on document sees every element.
      document.addEventListener('reveal:end', () => {
        revealed += 1
        render()
      })

      document.querySelector('#reset').addEventListener('click', () => {
        revealed = 0
        render()
        page.scrollTop = 0
        controller.destroy()
        controller = autoReveal({ root: page })
      })
    </script>
  </body>
</html>
05 / Controls

Show and hide from your own code

ControlsLive preview

Press Show to reveal the items now, even off screen, and Hide to put them back, or scroll the box. The controller returned by Reveal.auto() and autoReveal() has show() and hide(): show reveals now, with the transition and the cascade, even off screen; hide puts the elements back instantly. Reset starts over.

Scroll down, or press Show

One
Two
Three
Four
Try it
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>Show and hide from your own code</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 class="controls">
        <button id="show" type="button">Show</button>
        <button id="hide" type="button">Hide</button>
        <button id="reset" type="button">
          <svg
            width="16"
            height="16"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            aria-hidden="true"
          >
            <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
            <path d="M3 3v5h5" />
          </svg>
          Reset
        </button>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, or press Show</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
      </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
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
#reset {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}

JavaScript

main.js
const page = document.querySelector('#page')
let controller = Reveal.auto({ root: page, stagger: 80 })

document.querySelector('#show').addEventListener('click', () => controller.show())
document.querySelector('#hide').addEventListener('click', () => controller.hide())
document.querySelector('#reset').addEventListener('click', () => {
  page.scrollTop = 0
  controller = Reveal.auto({ root: page, stagger: 80 })
})

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>Show and hide from your own code</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/style.css"
    />
    <style>
      .controls {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
        margin-bottom: 0.75rem;
      }
      #reset {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
      }
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
    </style>
  </head>
  <body>
    <main>
      <div class="controls">
        <button id="show" type="button">Show</button>
        <button id="hide" type="button">Hide</button>
        <button id="reset" type="button">
          <svg
            width="16"
            height="16"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            aria-hidden="true"
          >
            <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
            <path d="M3 3v5h5" />
          </svg>
          Reset
        </button>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, or press Show</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      const page = document.querySelector('#page')
      let controller = Reveal.auto({ root: page, stagger: 80 })

      document.querySelector('#show').addEventListener('click', () => controller.show())
      document.querySelector('#hide').addEventListener('click', () => controller.hide())
      document.querySelector('#reset').addEventListener('click', () => {
        page.scrollTop = 0
        controller = Reveal.auto({ root: page, stagger: 80 })
      })
    </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>Show and hide from your own code</title>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <main>
      <div class="controls">
        <button id="show" type="button">Show</button>
        <button id="hide" type="button">Hide</button>
        <button id="reset" type="button">
          <svg
            width="16"
            height="16"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            aria-hidden="true"
          >
            <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
            <path d="M3 3v5h5" />
          </svg>
          Reset
        </button>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, or press Show</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
#reset {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}

JavaScript

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

const page = document.querySelector('#page')
let controller = autoReveal({ root: page, stagger: 80 })

document.querySelector('#show').addEventListener('click', () => controller.show())
document.querySelector('#hide').addEventListener('click', () => controller.hide())
document.querySelector('#reset').addEventListener('click', () => {
  page.scrollTop = 0
  controller.destroy()
  controller = autoReveal({ root: page, stagger: 80 })
})

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>Show and hide from your own code</title>
    <style>
      .controls {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
        margin-bottom: 0.75rem;
      }
      #reset {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
      }
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
    </style>
  </head>
  <body>
    <main>
      <div class="controls">
        <button id="show" type="button">Show</button>
        <button id="hide" type="button">Hide</button>
        <button id="reset" type="button">
          <svg
            width="16"
            height="16"
            viewBox="0 0 24 24"
            fill="none"
            stroke="currentColor"
            stroke-width="2"
            stroke-linecap="round"
            stroke-linejoin="round"
            aria-hidden="true"
          >
            <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
            <path d="M3 3v5h5" />
          </svg>
          Reset
        </button>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, or press Show</p>
        <div class="item" data-reveal>One</div>
        <div class="item" data-reveal>Two</div>
        <div class="item" data-reveal>Three</div>
        <div class="item" data-reveal>Four</div>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      const page = document.querySelector('#page')
      let controller = autoReveal({ root: page, stagger: 80 })

      document.querySelector('#show').addEventListener('click', () => controller.show())
      document.querySelector('#hide').addEventListener('click', () => controller.hide())
      document.querySelector('#reset').addEventListener('click', () => {
        page.scrollTop = 0
        controller.destroy()
        controller = autoReveal({ root: page, stagger: 80 })
      })
    </script>
  </body>
</html>
06 / Presets

Name your effects with presets and CSS

PresetsLive preview

Scroll the box down and back up. presets maps a data-reveal name to per-element options: its effect, duration, delay and more. Any other data-reveal value is left alone, so your own CSS can define an effect, and it fades when you define none.

Scroll down, then back up

hero: up blur, 900ms
card: zoom
card: zoom
tilt: your own CSS
Try it
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>Name your effects with presets and CSS</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, then back up</p>
        <div class="item" data-reveal="hero" data-reveal-repeat>hero: up blur, 900ms</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="tilt" data-reveal-repeat>tilt: your own CSS</div>
      </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;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}
/* An effect of your own: the script leaves the value alone. */
[data-reveal~='tilt'][data-reveal-state='pending'] {
  rotate: 8deg;
}

JavaScript

main.js
// Called before the DOM is ready, this replaces the automatic start.
Reveal.auto({
  root: document.querySelector('#page'),
  presets: {
    hero: { effect: 'up blur', duration: 900 },
    card: { effect: 'zoom', stagger: 90 },
  },
})

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>Name your effects with presets and CSS</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;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
      /* An effect of your own: the script leaves the value alone. */
      [data-reveal~='tilt'][data-reveal-state='pending'] {
        rotate: 8deg;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <div class="item" data-reveal="hero" data-reveal-repeat>hero: up blur, 900ms</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="tilt" data-reveal-repeat>tilt: your own CSS</div>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      // Called before the DOM is ready, this replaces the automatic start.
      Reveal.auto({
        root: document.querySelector('#page'),
        presets: {
          hero: { effect: 'up blur', duration: 900 },
          card: { effect: 'zoom', stagger: 90 },
        },
      })
    </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>Name your effects with presets and CSS</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, then back up</p>
        <div class="item" data-reveal="hero" data-reveal-repeat>hero: up blur, 900ms</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="tilt" data-reveal-repeat>tilt: your own CSS</div>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}
/* An effect of your own: the script leaves the value alone. */
[data-reveal~='tilt'][data-reveal-state='pending'] {
  rotate: 8deg;
}

JavaScript

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

autoReveal({
  root: document.querySelector('#page'),
  presets: {
    hero: { effect: 'up blur', duration: 900 },
    card: { effect: 'zoom', stagger: 90 },
  },
})

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>Name your effects with presets and CSS</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
      /* An effect of your own: the script leaves the value alone. */
      [data-reveal~='tilt'][data-reveal-state='pending'] {
        rotate: 8deg;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <div class="item" data-reveal="hero" data-reveal-repeat>hero: up blur, 900ms</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="card" data-reveal-repeat>card: zoom</div>
        <div class="item" data-reveal="tilt" data-reveal-repeat>tilt: your own CSS</div>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      autoReveal({
        root: document.querySelector('#page'),
        presets: {
          hero: { effect: 'up blur', duration: 900 },
          card: { effect: 'zoom', stagger: 90 },
        },
      })
    </script>
  </body>
</html>
07 / Conditions

Per-element conditions

ConditionsLive preview

Scroll the box to see which items animate. data-reveal-media only animates while a media query matches, data-reveal-threshold waits for more of the element, and data-reveal-reduced="fade" keeps only a fade, instead of nothing, for visitors who prefer reduced motion.

Scroll down

Animates from 40rem wide, shown as is below
Waits until 60% is visible
Slides and blurs in; only fades under reduced motion
Try it
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>Per-element conditions</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>
        <div class="item" data-reveal="left" data-reveal-media="(min-width: 40rem)">
          Animates from 40rem wide, shown as is below
        </div>
        <div class="item tall" data-reveal="up" data-reveal-threshold="0.6">
          Waits until 60% is visible
        </div>
        <div class="item" data-reveal="up blur" data-reveal-reduced="fade">
          Slides and blurs in; only fades under reduced motion
        </div>
      </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;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}
.tall {
  min-height: 8rem;
}

JavaScript

main.js
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>Per-element conditions</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;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
      .tall {
        min-height: 8rem;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <div class="item" data-reveal="left" data-reveal-media="(min-width: 40rem)">
          Animates from 40rem wide, shown as is below
        </div>
        <div class="item tall" data-reveal="up" data-reveal-threshold="0.6">
          Waits until 60% is visible
        </div>
        <div class="item" data-reveal="up blur" data-reveal-reduced="fade">
          Slides and blurs in; only fades under reduced motion
        </div>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      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>Per-element conditions</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>
        <div class="item" data-reveal="left" data-reveal-media="(min-width: 40rem)">
          Animates from 40rem wide, shown as is below
        </div>
        <div class="item tall" data-reveal="up" data-reveal-threshold="0.6">
          Waits until 60% is visible
        </div>
        <div class="item" data-reveal="up blur" data-reveal-reduced="fade">
          Slides and blurs in; only fades under reduced motion
        </div>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
}
.tall {
  min-height: 8rem;
}

JavaScript

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

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>Per-element conditions</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
      }
      .tall {
        min-height: 8rem;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down</p>
        <div class="item" data-reveal="left" data-reveal-media="(min-width: 40rem)">
          Animates from 40rem wide, shown as is below
        </div>
        <div class="item tall" data-reveal="up" data-reveal-threshold="0.6">
          Waits until 60% is visible
        </div>
        <div class="item" data-reveal="up blur" data-reveal-reduced="fade">
          Slides and blurs in; only fades under reduced motion
        </div>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      autoReveal({ root: document.querySelector('#page') })
    </script>
  </body>
</html>
08 / Stagger

Choose where a cascade starts

StaggerLive preview

Choose an origin in From, an easing in Ease, or switch Grid, then scroll the box down and back up. data-reveal-stagger-from picks the origin (start, end, center, edges, random), data-reveal-stagger-grid measures rows and columns instead of a line, and data-reveal-stagger-ease spaces the gaps. Each change restarts the cascade.

Scroll down, then back up

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
Try it
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>Choose where a cascade starts</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 class="controls">
        <label
          >From
          <select id="from">
            <option>start</option>
            <option>end</option>
            <option selected>center</option>
            <option>edges</option>
            <option>random</option>
          </select>
        </label>
        <label
          >Ease
          <select id="ease">
            <option>linear</option>
            <option>out</option>
          </select>
        </label>
        <label><input id="grid-mode" type="checkbox" checked /> Grid</label>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <ul
          id="tiles"
          data-reveal-stagger="70"
          data-reveal-stagger-grid
          data-reveal-stagger-from="center"
        >
          <li data-reveal="zoom" data-reveal-repeat>1</li>
          <li data-reveal="zoom" data-reveal-repeat>2</li>
          <li data-reveal="zoom" data-reveal-repeat>3</li>
          <li data-reveal="zoom" data-reveal-repeat>4</li>
          <li data-reveal="zoom" data-reveal-repeat>5</li>
          <li data-reveal="zoom" data-reveal-repeat>6</li>
          <li data-reveal="zoom" data-reveal-repeat>7</li>
          <li data-reveal="zoom" data-reveal-repeat>8</li>
          <li data-reveal="zoom" data-reveal-repeat>9</li>
          <li data-reveal="zoom" data-reveal-repeat>10</li>
          <li data-reveal="zoom" data-reveal-repeat>11</li>
          <li data-reveal="zoom" data-reveal-repeat>12</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
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
}
#page {
  height: 16rem;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
#tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}
#tiles li {
  padding: 1.25rem;
  background: #f3f3f3;
}

JavaScript

main.js
const page = document.querySelector('#page')
const tiles = document.querySelector('#tiles')

// The container's attributes are read when Reveal starts, so start it again
// after a change. Reveal.auto() replaces the previous run.
const start = () => {
  tiles.setAttribute('data-reveal-stagger-from', document.querySelector('#from').value)
  tiles.setAttribute('data-reveal-stagger-ease', document.querySelector('#ease').value)
  tiles.toggleAttribute('data-reveal-stagger-grid', document.querySelector('#grid-mode').checked)
  page.scrollTop = 0
  Reveal.auto({ root: page })
}

document.querySelector('.controls').addEventListener('change', start)
start()

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>Choose where a cascade starts</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/style.css"
    />
    <style>
      .controls {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: center;
        margin-bottom: 0.75rem;
      }
      .controls label {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        min-height: 2.75rem;
      }
      #page {
        height: 16rem;
        overflow-y: auto;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      #tiles {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.75rem;
      }
      #tiles li {
        padding: 1.25rem;
        background: #f3f3f3;
      }
    </style>
  </head>
  <body>
    <main>
      <div class="controls">
        <label
          >From
          <select id="from">
            <option>start</option>
            <option>end</option>
            <option selected>center</option>
            <option>edges</option>
            <option>random</option>
          </select>
        </label>
        <label
          >Ease
          <select id="ease">
            <option>linear</option>
            <option>out</option>
          </select>
        </label>
        <label><input id="grid-mode" type="checkbox" checked /> Grid</label>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <ul
          id="tiles"
          data-reveal-stagger="70"
          data-reveal-stagger-grid
          data-reveal-stagger-from="center"
        >
          <li data-reveal="zoom" data-reveal-repeat>1</li>
          <li data-reveal="zoom" data-reveal-repeat>2</li>
          <li data-reveal="zoom" data-reveal-repeat>3</li>
          <li data-reveal="zoom" data-reveal-repeat>4</li>
          <li data-reveal="zoom" data-reveal-repeat>5</li>
          <li data-reveal="zoom" data-reveal-repeat>6</li>
          <li data-reveal="zoom" data-reveal-repeat>7</li>
          <li data-reveal="zoom" data-reveal-repeat>8</li>
          <li data-reveal="zoom" data-reveal-repeat>9</li>
          <li data-reveal="zoom" data-reveal-repeat>10</li>
          <li data-reveal="zoom" data-reveal-repeat>11</li>
          <li data-reveal="zoom" data-reveal-repeat>12</li>
        </ul>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      const page = document.querySelector('#page')
      const tiles = document.querySelector('#tiles')

      // The container's attributes are read when Reveal starts, so start it again
      // after a change. Reveal.auto() replaces the previous run.
      const start = () => {
        tiles.setAttribute('data-reveal-stagger-from', document.querySelector('#from').value)
        tiles.setAttribute('data-reveal-stagger-ease', document.querySelector('#ease').value)
        tiles.toggleAttribute(
          'data-reveal-stagger-grid',
          document.querySelector('#grid-mode').checked
        )
        page.scrollTop = 0
        Reveal.auto({ root: page })
      }

      document.querySelector('.controls').addEventListener('change', start)
      start()
    </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>Choose where a cascade starts</title>
    <link rel="stylesheet" href="./style.css" />
  </head>
  <body>
    <main>
      <div class="controls">
        <label
          >From
          <select id="from">
            <option>start</option>
            <option>end</option>
            <option selected>center</option>
            <option>edges</option>
            <option>random</option>
          </select>
        </label>
        <label
          >Ease
          <select id="ease">
            <option>linear</option>
            <option>out</option>
          </select>
        </label>
        <label><input id="grid-mode" type="checkbox" checked /> Grid</label>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <ul
          id="tiles"
          data-reveal-stagger="70"
          data-reveal-stagger-grid
          data-reveal-stagger-from="center"
        >
          <li data-reveal="zoom" data-reveal-repeat>1</li>
          <li data-reveal="zoom" data-reveal-repeat>2</li>
          <li data-reveal="zoom" data-reveal-repeat>3</li>
          <li data-reveal="zoom" data-reveal-repeat>4</li>
          <li data-reveal="zoom" data-reveal-repeat>5</li>
          <li data-reveal="zoom" data-reveal-repeat>6</li>
          <li data-reveal="zoom" data-reveal-repeat>7</li>
          <li data-reveal="zoom" data-reveal-repeat>8</li>
          <li data-reveal="zoom" data-reveal-repeat>9</li>
          <li data-reveal="zoom" data-reveal-repeat>10</li>
          <li data-reveal="zoom" data-reveal-repeat>11</li>
          <li data-reveal="zoom" data-reveal-repeat>12</li>
        </ul>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
}
#page {
  height: 16rem;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
#tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}
#tiles li {
  padding: 1.25rem;
  background: #f3f3f3;
}

JavaScript

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

const page = document.querySelector('#page')
const tiles = document.querySelector('#tiles')
let controller = null

// The container's attributes are read when Reveal starts, so start it again
// after a change.
const start = () => {
  controller?.destroy()
  tiles.setAttribute('data-reveal-stagger-from', document.querySelector('#from').value)
  tiles.setAttribute('data-reveal-stagger-ease', document.querySelector('#ease').value)
  tiles.toggleAttribute('data-reveal-stagger-grid', document.querySelector('#grid-mode').checked)
  page.scrollTop = 0
  controller = autoReveal({ root: page })
}

document.querySelector('.controls').addEventListener('change', start)
start()

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>Choose where a cascade starts</title>
    <style>
      .controls {
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: center;
        margin-bottom: 0.75rem;
      }
      .controls label {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        min-height: 2.75rem;
      }
      #page {
        height: 16rem;
        overflow-y: auto;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      #tiles {
        list-style: none;
        margin: 0;
        padding: 0;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.75rem;
      }
      #tiles li {
        padding: 1.25rem;
        background: #f3f3f3;
      }
    </style>
  </head>
  <body>
    <main>
      <div class="controls">
        <label
          >From
          <select id="from">
            <option>start</option>
            <option>end</option>
            <option selected>center</option>
            <option>edges</option>
            <option>random</option>
          </select>
        </label>
        <label
          >Ease
          <select id="ease">
            <option>linear</option>
            <option>out</option>
          </select>
        </label>
        <label><input id="grid-mode" type="checkbox" checked /> Grid</label>
      </div>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <ul
          id="tiles"
          data-reveal-stagger="70"
          data-reveal-stagger-grid
          data-reveal-stagger-from="center"
        >
          <li data-reveal="zoom" data-reveal-repeat>1</li>
          <li data-reveal="zoom" data-reveal-repeat>2</li>
          <li data-reveal="zoom" data-reveal-repeat>3</li>
          <li data-reveal="zoom" data-reveal-repeat>4</li>
          <li data-reveal="zoom" data-reveal-repeat>5</li>
          <li data-reveal="zoom" data-reveal-repeat>6</li>
          <li data-reveal="zoom" data-reveal-repeat>7</li>
          <li data-reveal="zoom" data-reveal-repeat>8</li>
          <li data-reveal="zoom" data-reveal-repeat>9</li>
          <li data-reveal="zoom" data-reveal-repeat>10</li>
          <li data-reveal="zoom" data-reveal-repeat>11</li>
          <li data-reveal="zoom" data-reveal-repeat>12</li>
        </ul>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      const page = document.querySelector('#page')
      const tiles = document.querySelector('#tiles')
      let controller = null

      // The container's attributes are read when Reveal starts, so start it again
      // after a change.
      const start = () => {
        controller?.destroy()
        tiles.setAttribute('data-reveal-stagger-from', document.querySelector('#from').value)
        tiles.setAttribute('data-reveal-stagger-ease', document.querySelector('#ease').value)
        tiles.toggleAttribute(
          'data-reveal-stagger-grid',
          document.querySelector('#grid-mode').checked
        )
        page.scrollTop = 0
        controller = autoReveal({ root: page })
      }

      document.querySelector('.controls').addEventListener('change', start)
      start()
    </script>
  </body>
</html>
09 / Split text

Reveal text word by word or character by character

Split textLive preview

Scroll the box to see the text arrive piece by piece. data-reveal-split="words" or "chars" animates the text piece by piece with the element's effect. Screen readers get the original text, graphemes (accents, emoji with skin tone) and Japanese stay intact, and elements with links or buttons are revealed as a whole.

Scroll down, then back up

Motion that respects the reader

Split by characters

Café déjà vu 👍🏽 日本語のテキスト

Try it
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>Reveal text word by word or character by character</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, then back up</p>
        <h2 data-reveal="up blur" data-reveal-split="words" data-reveal-repeat>
          Motion that respects the reader
        </h2>
        <p data-reveal="up" data-reveal-split="chars" data-reveal-repeat>Split by characters</p>
        <p data-reveal="zoom" data-reveal-split="chars" data-reveal-repeat>
          Café déjà vu 👍🏽 日本語のテキスト
        </p>
      </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;
  display: grid;
  gap: 1rem;
  align-content: start;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
h2,
p {
  margin: 0;
}

JavaScript

main.js
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>Reveal text word by word or character by character</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;
        display: grid;
        gap: 1rem;
        align-content: start;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      h2,
      p {
        margin: 0;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <h2 data-reveal="up blur" data-reveal-split="words" data-reveal-repeat>
          Motion that respects the reader
        </h2>
        <p data-reveal="up" data-reveal-split="chars" data-reveal-repeat>Split by characters</p>
        <p data-reveal="zoom" data-reveal-split="chars" data-reveal-repeat>
          Café déjà vu 👍🏽 日本語のテキスト
        </p>
      </div>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      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>Reveal text word by word or character by character</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, then back up</p>
        <h2 data-reveal="up blur" data-reveal-split="words" data-reveal-repeat>
          Motion that respects the reader
        </h2>
        <p data-reveal="up" data-reveal-split="chars" data-reveal-repeat>Split by characters</p>
        <p data-reveal="zoom" data-reveal-split="chars" data-reveal-repeat>
          Café déjà vu 👍🏽 日本語のテキスト
        </p>
      </div>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 1rem;
  align-content: start;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
h2,
p {
  margin: 0;
}

JavaScript

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

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>Reveal text word by word or character by character</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 1rem;
        align-content: start;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      h2,
      p {
        margin: 0;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll down, then back up</p>
        <h2 data-reveal="up blur" data-reveal-split="words" data-reveal-repeat>
          Motion that respects the reader
        </h2>
        <p data-reveal="up" data-reveal-split="chars" data-reveal-repeat>Split by characters</p>
        <p data-reveal="zoom" data-reveal-split="chars" data-reveal-repeat>
          Café déjà vu 👍🏽 日本語のテキスト
        </p>
      </div>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      autoReveal({ root: document.querySelector('#page') })
    </script>
  </body>
</html>
10 / Scrub

Follow the scroll position with CSS only

ScrubLive preview

Scroll the box slowly: the effect follows your position. data-reveal-scrub ties the effect to the scroll position with a scroll-driven animation, no JavaScript involved. Browsers without animation-timeline show the content as is.

Scroll slowly

zoom
left
blur

Try it
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>Follow the scroll position with CSS only</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 slowly</p>
        <div class="item" data-reveal="zoom" data-reveal-scrub>zoom</div>
        <div class="item" data-reveal="left" data-reveal-scrub>left</div>
        <div class="item" data-reveal="blur" data-reveal-scrub>blur</div>
        <p class="spacer"></p>
      </div>
      <p id="support"></p>
    </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;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
  --reveal-range: entry 0% cover 40%;
}

JavaScript

main.js
document.querySelector('#support').textContent = CSS.supports(
  '(animation-timeline: view()) and (animation-range: entry)'
)
  ? 'Scroll-driven animations are supported here.'
  : 'This browser has no scroll-driven animations, so the content stays visible.'

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>Follow the scroll position with CSS only</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;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
        --reveal-range: entry 0% cover 40%;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll slowly</p>
        <div class="item" data-reveal="zoom" data-reveal-scrub>zoom</div>
        <div class="item" data-reveal="left" data-reveal-scrub>left</div>
        <div class="item" data-reveal="blur" data-reveal-scrub>blur</div>
        <p class="spacer"></p>
      </div>
      <p id="support"></p>
    </main>
    <script src="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/browser/reveal.global.js"></script>
    <script>
      document.querySelector('#support').textContent = CSS.supports(
        '(animation-timeline: view()) and (animation-range: entry)'
      )
        ? 'Scroll-driven animations are supported here.'
        : 'This browser has no scroll-driven animations, so the content stays visible.'
    </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>Follow the scroll position with CSS only</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 slowly</p>
        <div class="item" data-reveal="zoom" data-reveal-scrub>zoom</div>
        <div class="item" data-reveal="left" data-reveal-scrub>left</div>
        <div class="item" data-reveal="blur" data-reveal-scrub>blur</div>
        <p class="spacer"></p>
      </div>
      <p id="support"></p>
    </main>
    <script type="module" src="./main.js"></script>
  </body>
</html>

CSS

style.css
#page {
  height: 16rem;
  overflow-y: auto;
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ccc;
}
.spacer {
  min-height: 24rem;
  margin: 0;
}
.item {
  padding: 1.25rem;
  background: #f3f3f3;
  --reveal-range: entry 0% cover 40%;
}

JavaScript

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

document.querySelector('#support').textContent = CSS.supports(
  '(animation-timeline: view()) and (animation-range: entry)'
)
  ? 'Scroll-driven animations are supported here.'
  : 'This browser has no scroll-driven animations, so the content stays visible.'

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>Follow the scroll position with CSS only</title>
    <style>
      #page {
        height: 16rem;
        overflow-y: auto;
        display: grid;
        gap: 0.75rem;
        padding: 1rem;
        border: 1px solid #ccc;
      }
      .spacer {
        min-height: 24rem;
        margin: 0;
      }
      .item {
        padding: 1.25rem;
        background: #f3f3f3;
        --reveal-range: entry 0% cover 40%;
      }
    </style>
  </head>
  <body>
    <main>
      <div id="page" tabindex="0" role="region" aria-label="Scrollable page">
        <p class="spacer">Scroll slowly</p>
        <div class="item" data-reveal="zoom" data-reveal-scrub>zoom</div>
        <div class="item" data-reveal="left" data-reveal-scrub>left</div>
        <div class="item" data-reveal="blur" data-reveal-scrub>blur</div>
        <p class="spacer"></p>
      </div>
      <p id="support"></p>
    </main>
    <script type="module">
      import { autoReveal } from '@samline/reveal'
      import '@samline/reveal/style.css'

      document.querySelector('#support').textContent = CSS.supports(
        '(animation-timeline: view()) and (animation-range: entry)'
      )
        ? 'Scroll-driven animations are supported here.'
        : 'This browser has no scroll-driven animations, so the content stays visible.'
    </script>
  </body>
</html>

These examples show a few possibilities. The next ideas are yours: combine the package’s capabilities with your own content, design and interactions to create the experience your project needs.

Read the example guideDownload the Reveal skill for AI agents
@samline/reveal

Reveal elements once as they scroll into view, with CSS effects, stagger, repeat and a CSS-only scrub mode, for vanilla JavaScript, any framework and plain HTML.

v2.0.0·MIT

Explore

DocsInstallation guideWorking examples

Project

Reveal skill for AI agentsGitHub(opens in a new tab)Changelognpm(opens in a new tab)License(opens in a new tab)

© 2026 samline · Made for the open web.

Back to top