Behaviors
Motion
One place that answers “may things move?”.
Usage#
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.
<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>| Name | Signature | Description |
|---|---|---|
motionAllowed | () => boolean | Not reduced, not paused. |
prefersReducedMotion | () => boolean | The media query. |
getMotion / setMotion | (state) => void | "on" or "off". setMotion can persist to a storage key. |
onMotionChange | (callback) => unsubscribe | Fires for the media query and for the pause switch. |
initMotionSwitch | ({ selector?, storageKey? }) => destroy | Wire the buttons. aria-pressed true means paused. |