data-trigger
Controls when effects activate. Separates effect behavior from activation timing.
Overview
The data-trigger attribute controls when an effect activates. It separates the visual effect from its activation moment, allowing the same effect to be triggered by scroll, hover, click, or a timed delay.
If no data-trigger is set, CSS-only effects activate immediately and JS effects run on load.
scroll
Activates when the element scrolls into the viewport (10% visible threshold). Uses IntersectionObserver and fires once.
hover
Activates on pointer enter, deactivates on pointer leave. For CSS-only effects, the :hover pseudo-class drives the animation directly.
click
Toggles the effect on click. Adds [data-effect-active] on first click, removes it on second.
time:n
Activates after a delay of n milliseconds. Uses setTimeout.
No trigger (immediate)
When data-trigger is omitted, CSS-only effects activate immediately via their CSS selectors. JS effects run their activate() function on initialization.
Trigger independence
An effect doesn't know what triggered it. The same fade-in slide-up effect behaves identically whether activated by scroll, hover, click, or a timer.
Custom triggers
Register custom triggers via the VB.trigger() API. Custom triggers work identically to built-in ones.
Attribute reference
| Trigger | Implementation | Notes |
|---|---|---|
scroll | IntersectionObserver | Fires once at 10% visible, then disconnects. |
hover | CSS :hover + JS events | CSS-only effects use :hover. JS effects use pointer events. |
click | addEventListener('click') | Toggles [data-effect-active]. |
time:n | setTimeout | n is delay in milliseconds. |