Behaviors
Reveal
Content fades up as it enters the screen, and is never left invisible.
Usage#
<section class="ha-reveal">First block</section>
<section class="ha-reveal" style="--ha-i:1">Second block, 80ms later</section>The blocks on this page use the same script. Scroll the landing page to see it.
import { startReveal } from '@originlabsbr/halora/reveal';
const stop = startReveal(); // idempotent: call after each render
startReveal({ selector: '[data-reveal]', visibleClass: 'in' });
stop(); // disconnect observersThe rules#
- Hidden only when it can run. The hidden state lives under
html.ha-reveal-on, which the script adds only when JavaScript runs, motion is allowed, andIntersectionObserverexists. A failed script, reduced motion, or the pause switch leaves everything visible. - Any pixel reveals. The observer uses
threshold: 0and no negativerootMargin. A negative margin leaves elements that stop in that band invisible while on screen. - On every call. Elements already on screen animate in at once; elements above the viewport appear without a transition. Calling
startReveal()again tears down the old observer and rescans. - New nodes count. A
MutationObserverpicks up elements that are rendered later, such as cards remounted after a language switch. - Fallbacks. Print, no
IntersectionObserver, reduced motion, and the pause switch all reveal everything. - Motion. 24px or less of travel, 700ms, the shared easing, and a stagger of at most 240ms through
--ha-i.
API#
| Name | Signature | Description |
|---|---|---|
startReveal | (options?) => teardown | Start or restart. Options: root, selector, visibleClass, instantClass, observeMutations. |
revealAll | (options?) => void | Show everything now and drop the hidden state. |
initialState | (rect, viewportHeight) => "instant" | "now" | "wait" | Pure rule used for the first pass. |
canReveal | () => boolean | Whether the hidden state may be used. |
CSS#
html.ha-reveal-on .ha-reveal:not(.is-visible) {
opacity: 0;
transform: translateY(var(--ha-reveal-distance));
}