- Docs
- Scrub mode
Scrub mode
Tie a @samline/reveal effect to the scroll position with a CSS scroll-driven animation, set its range and know what other browsers show.
data-reveal-scrub plays the effect along the scroll position instead of on entry: halfway through the range, the element is halfway revealed, and scrolling back reverses it. It is a CSS scroll-driven animation (animation-timeline: view()); the script ignores these elements, so it works with the stylesheet alone.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@samline/reveal@2.0.0/dist/style.css" />
<figure data-reveal="zoom" data-reveal-scrub>…</figure>
Range
--reveal-range sets when the animation runs, as an animation-range value. The default, entry 0% entry 100%, reveals the element while it enters the viewport.
figure {
/* Start as it enters, finish when 40% of the way through the viewport. */
--reveal-range: entry 0% cover 40%;
}
Composed effects (data-reveal="up blur"), rotate and the wipes (wipe-up fade) scrub too. The effect variables still apply: --reveal-distance, --reveal-scale, --reveal-blur and --reveal-rotate. Easing presets, events and data-reveal-reduced belong to the script, so they do not apply to scrub. Durations and easing do not, because the scroll position drives the animation.
Support
- Browsers with scroll-driven animations play the scrub.
- Other browsers, and visitors with
prefers-reduced-motion: reduce, see the element as is. - Inside a scroll container, the closest scrolling ancestor drives the animation.
To detect support in JavaScript, use CSS.supports('(animation-timeline: view()) and (animation-range: entry)').