Skip to content
Halorav0.1.0

Behaviors

Motion

One place that answers “may things move?”.

Usage#

JavaScript
import { initMotionSwitch, motionAllowed, onMotionChange } from '@originlabsbr/halora/motion';

initMotionSwitch({ storageKey: null });   // wire [data-ha-motion-toggle]

if (motionAllowed()) startMarquee();
const off = onMotionChange((allowed) => (allowed ? start() : stop()));

Motion is allowed when the visitor has not asked for reduced motion and has not paused animations. The pause switch sets data-motion="off" on the root. The base CSS then disables animations and transitions, and reveal and particles stop.

HTML
<button type="button" class="ha-motion-toggle" data-ha-motion-toggle aria-pressed="false"><span class="ha-motion-toggle__pause"><svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" focusable="false"><rect x="6" y="5" width="4" height="14" rx="1"/><rect x="14" y="5" width="4" height="14" rx="1"/></svg></span><span class="ha-motion-toggle__play"><svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" focusable="false"><path d="M8 5v14l11-7z"/></svg></span>Pause animations</button>
NameSignatureDescription
motionAllowed() => booleanNot reduced, not paused.
prefersReducedMotion() => booleanThe media query.
getMotion / setMotion(state) => void"on" or "off". setMotion can persist to a storage key.
onMotionChange(callback) => unsubscribeFires for the media query and for the pause switch.
initMotionSwitch({ selector?, storageKey? }) => destroyWire the buttons. aria-pressed true means paused.

Edit this page on GitHub

Type to search.