Skip to content
Halorav0.1.0

Behaviors

Reveal

Content fades up as it enters the screen, and is never left invisible.

Usage#

First block
Second block, 80ms later
HTML
<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.

JavaScript
import { startReveal } from '@originlabsbr/halora/reveal';

const stop = startReveal();          // idempotent: call after each render
startReveal({ selector: '[data-reveal]', visibleClass: 'in' });
stop();                              // disconnect observers

The 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, and IntersectionObserver exists. A failed script, reduced motion, or the pause switch leaves everything visible.
  • Any pixel reveals. The observer uses threshold: 0 and no negative rootMargin. 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 MutationObserver picks 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#

NameSignatureDescription
startReveal(options?) => teardownStart or restart. Options: root, selector, visibleClass, instantClass, observeMutations.
revealAll(options?) => voidShow everything now and drop the hidden state.
initialState(rect, viewportHeight) => "instant" | "now" | "wait"Pure rule used for the first pass.
canReveal() => booleanWhether the hidden state may be used.

CSS#

CSS
html.ha-reveal-on .ha-reveal:not(.is-visible) {
  opacity: 0;
  transform: translateY(var(--ha-reveal-distance));
}

Edit this page on GitHub

Type to search.