- Docs
- Effects and timing
Effects and timing
Tune the built-in @samline/reveal effects, write your own starting point in CSS, cascade groups and replay elements on every entry.
Tune an effect
Every effect starts from a hidden state and transitions to the element’s normal style. Change how far, how long and how it eases with attributes or custom properties:
<h2 data-reveal="left" data-reveal-distance="3rem" data-reveal-duration="900">Title</h2>
.hero {
--reveal-duration: 1s;
--reveal-easing: cubic-bezier(0.16, 1, 0.3, 1);
--reveal-scale: 0.8; /* zoom */
--reveal-blur: 16px; /* blur */
}
Combine effects
Separate effects with spaces. Each property family is independent, so the order does not matter:
<h2 data-reveal="up blur">Slides up and sharpens</h2>
<img data-reveal="zoom fade" alt="" src="photo.jpg" />
<p data-reveal="left rotate">Slides in with a slight turn</p>
Use one direction (up, down, left, right) and one wipe at most; up left is not supported. rotate starts at --reveal-rotate (default -3deg).
Wipes
wipe-up, wipe-down, wipe-left and wipe-right uncover the element with a clip-path. A wipe alone does not fade, so add fade for both:
<figure data-reveal="wipe-up">Uncovered from the bottom</figure>
<figure data-reveal="wipe-left fade">Uncovered from the right, fading in</figure>
clip-path is only set on wipe elements while they are pending or revealing, so your own clip-path is untouched once they are revealed.
Easing presets
data-reveal-easing (or the easing option) takes smooth (the default), snappy, spring or bounce. Springs and bounces need room to settle: use 800 to 1000 ms. Opacity and wipes keep a curve without overshoot, so they never flicker or re-cover.
<li data-reveal data-reveal-easing="spring" data-reveal-duration="900">Springs in</li>
Any other value is a CSS timing function, set as --reveal-easing: data-reveal-easing="cubic-bezier(0.7, 0, 0.3, 1)". Without JavaScript, the preset attributes still work in CSS.
Your own starting point
Elements waiting to enter have data-reveal-state="pending". Style that state to change where an effect starts. The stylesheet uses :where(), so your rule wins without !important:
.card[data-reveal-state='pending'] {
opacity: 0;
translate: 0 2rem;
scale: 0.9;
filter: saturate(0);
}
During the reveal, the stylesheet transitions opacity, translate, scale, rotate, filter and clip-path. To animate other properties, add them while revealing:
.card[data-reveal-state='pending'] {
background-color: transparent;
}
.card[data-reveal-state='revealing'] {
transition-property: opacity, translate, scale, rotate, filter, clip-path, background-color;
}
Effects use the individual translate, scale, rotate and filter properties, never transform, so an element’s own transform keeps working.
Your own effects and presets
A data-reveal value that is not a built-in effect is left as it is, so your CSS can define it. Without CSS of its own an unknown name simply fades. Only an empty or missing value takes the effect option.
[data-reveal~='tilt'][data-reveal-state='pending'] {
rotate: 8deg;
}
The presets option gives a name to a set of per-element options, so markup stays short. Precedence: the element’s attributes, then the preset, then the options of the call. A preset holds only per-element options (no root, callbacks or presets), The preset name must be the whole data-reveal value (hero, not hero up), and only the names you define match.
autoReveal({
presets: {
hero: { effect: 'up blur', duration: 900 },
card: { effect: 'zoom', stagger: 90 },
},
})
<h1 data-reveal="hero">Headline</h1>
The original data-reveal value comes back on destroy().
Cascades
Put data-reveal-stagger on a container to delay each element that enters together with the others, in document order:
<ul data-reveal-stagger="80">
<li data-reveal>First, no delay</li>
<li data-reveal>Second, 80ms</li>
<li data-reveal data-reveal-delay="100">Third, 100ms + 160ms</li>
</ul>
The cascade adds to each element’s own delay. Elements that enter in different frames are not delayed, so content scrolled in one by one appears right away. Without a container, the stagger option cascades the elements of one call.
Cascade patterns
Four more attributes on the same container shape the cascade. Each has a matching option (staggerFrom, staggerGrid, staggerEase, staggerMax) for elements without a container; the attribute wins.
<ul
data-reveal-stagger="60"
data-reveal-stagger-from="center"
data-reveal-stagger-grid
data-reveal-stagger-ease="out"
data-reveal-stagger-max="800"
>
...
</ul>
data-reveal-stagger-from:start(default, document order),end,center(the middle leads),edges(the ends lead) orrandom.data-reveal-stagger-grid: cascade over rows and columns instead of a line. Rows and columns come from each item’s layout position (offsetTopandoffsetLeft, which ignore the pending translate; values within 2px share a row or column).startbecomes a diagonal wave from the top-left,centerandedgesuse the distance from the grid’s center.data-reveal-stagger-ease:linear(default), orout(gaps shrink as the cascade goes on, which reads organic; recommended for long cascades). The total length stays the same.data-reveal-stagger-max: longest cascade in milliseconds; a longer one is scaled down to fit.
Only elements revealed in the same frame cascade, as before. Without these attributes nothing changes.
Split text
data-reveal-split="words" or "chars" (or the split option) animates an element’s text piece by piece with the element’s effect. The element itself does not animate: each word, or each character (grapheme, so accents and emoji with skin tone stay whole), enters one after another.
<h2 data-reveal="up blur" data-reveal-split="words">Motion that respects the reader</h2>
<p data-reveal="zoom" data-reveal-split="chars" data-reveal-split-stagger="30">Café déjà vu</p>
- Words step 50ms apart and characters 20ms. Set
data-reveal-split-stagger(or--reveal-split-stagger) to change it. The whole cascade is capped at 800ms (data-reveal-split-max,0for no cap): longer text gets a smaller step. The CSS does the math,min(step, max / (pieces - 1)). charsfalls back towordsabove 400 characters. Joining scripts such as Arabic keep each word whole, because cutting them apart breaks their shapes.- Text is split only the first time the element is hidden, so content already in view, and elements shown as is (reduced motion,
data-reveal-media), are never touched. It stays split after the reveal, because joining it again would shift the kerning. The cleanup restores the original markup. - Punctuation stays with its word, so a line never breaks before a comma. With
chars, each word is kept whole on a line. - Text inside inline formatting (
em,strong,span,mark,code,u,deland similar) is split too, andbris kept; underline and line-through are kept as well. - Kerning and ligatures are lost in
charsmode, because every character becomes its own box. Preferwords, and for characters preferup,fadeor a wipe overblur, which is expensive and shows the seams. - Do not change the content of a split element while it is active (
innerHTML,textContent, a framework render): the split markup is not rebuilt. The cleanup never throws if you did, and leaves your new content alone. - Only text with plain inline formatting and
bris split. An element with anything else inside (links, buttons, images, nested blocks, a nested[data-reveal]or[lang], focusable or editable content) is revealed as a whole, untouched, and so aredata-reveal-scrubelements. The decision is made before any change, so nothing is lost: an image’saltstays where it was. - The element’s children are wrapped in a
span, so use it on text blocks (headings, paragraphs), not on flex or grid containers. Delays compose: a cascade ordata-reveal-delayon the element is added to each piece’s own delay. onShowfires for the element when its pieces start;onEndandreveal:endfire once the last piece has finished. The events are for the element, never for its pieces, andreveal()ignores the generated markup, even with a broad selector such asspan.
Replay on every entry
data-reveal-repeat (or repeat: true) hides an element again when it leaves, and reveals it each time it comes back, from either direction. Elements above the viewport on load are hidden too, so they play on the way back up.
reveal('.stat', {
effect: 'zoom',
repeat: true,
onShow: stat => stat.classList.add('is-counting'),
onHide: stat => stat.classList.remove('is-counting'),
})
Per-element conditions
data-reveal-threshold and data-reveal-margin override threshold and rootMargin for one element. data-reveal-media="(min-width: 40rem)" animates it only while the query matches; otherwise it is shown as is, and a pending element is shown when the query stops matching.
When reveals start
By default a reveal starts 64px before the element enters (rootMargin: '0px 0px 64px 0px'), so it is moving by the time it is visible. To wait until part of it is in view, shrink the root or raise the threshold:
autoReveal({ rootMargin: '0px 0px -10% 0px', threshold: 0.2 })
Inside a scroll container, pass it as root.