Reveal examples.
Live previews of distinct scenarios, each with independently copyable files. The same examples appear in the documentation.
Each preview runs the real package. The copied files load the published browser bundle, so they run as they are.
Cascade a grid as it scrolls in
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
<!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
#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
// 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
<!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
<!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
#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
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
<!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>
Every effect, replayed on each entry
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
Explore the code
HTML / CDN
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
#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
Reveal.auto({ root: document.querySelector('#page') })
Complete file
<!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
<!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
#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
import { autoReveal } from '@samline/reveal'
import '@samline/reveal/style.css'
autoReveal({ root: document.querySelector('#page') })
Complete file
<!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>
Combine effects and pick an easing
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
Explore the code
HTML / CDN
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
#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
Reveal.auto({ root: document.querySelector('#page') })
Complete file
<!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
<!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
#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
import { autoReveal } from '@samline/reveal'
import '@samline/reveal/style.css'
autoReveal({ root: document.querySelector('#page') })
Complete file
<!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>
Count reveals with lifecycle events
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
Explore the code
HTML / CDN
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
#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
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
<!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
<!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
#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
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
<!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>
Show and hide from your own code
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
Explore the code
HTML / CDN
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
.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
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
<!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
<!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
.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
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
<!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>
Name your effects with presets and CSS
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
Explore the code
HTML / CDN
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
#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
// 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
<!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
<!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
#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
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
<!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>
Per-element conditions
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
Explore the code
HTML / CDN
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
#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
Reveal.auto({ root: document.querySelector('#page') })
Complete file
<!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
<!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
#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
import { autoReveal } from '@samline/reveal'
import '@samline/reveal/style.css'
autoReveal({ root: document.querySelector('#page') })
Complete file
<!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>
Choose where a cascade starts
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
Explore the code
HTML / CDN
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
.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
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
<!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
<!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
.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
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
<!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>
Reveal text word by word or character by character
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 👍🏽 日本語のテキスト
Explore the code
HTML / CDN
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
#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
Reveal.auto({ root: document.querySelector('#page') })
Complete file
<!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
<!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
#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
import { autoReveal } from '@samline/reveal'
import '@samline/reveal/style.css'
autoReveal({ root: document.querySelector('#page') })
Complete file
<!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>
Follow the scroll position with CSS only
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
Explore the code
HTML / CDN
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
#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
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
<!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
<!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
#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
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
<!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