Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

data-trigger

Controls when a data-effect activates: on scroll, hover or focus, click, after a delay, on a media query, an event, a view transition, or continuously with scroll position.

Overview

data-trigger decides when an element's data-effect activates. The effect describes what moves; the trigger describes the moment. The same fade-in slide-up runs identically whether a scroll, a click or a timer starts it.

Without data-trigger the effect plays as soon as the page loads. With a trigger, the runtime adds data-effect-active to the element when the trigger fires, and the effect's CSS and JavaScript react to that attribute.

Usage

  • Put data-trigger on the same element as data-effect. Children of a data-stagger container each need their own pair.
  • Several triggers can be listed, separated by spaces. Any of them activates the effect: data-trigger="scroll time:3000" plays on scroll or after three seconds, whichever comes first.
  • A value takes a parameter after its first colon (time:2000, media:(min-width:60rem)). Because values are split on spaces, a parameter cannot contain one.
  • The trigger handlers ship in every Vanilla Breeze script bundle that contains the effects runtime (core, extras, the full and autoload bundles, and the effects pack).

Options

ValueActivatesDeactivatesNotes
scroll Once, when 10% of the element is in the viewport (IntersectionObserver). Never. Same as intersect. Under reduced motion it activates immediately.
intersect, intersect:once Once, on first viewport entry. Never. Under reduced motion it activates immediately.
intersect:toggle Every time the element enters the viewport. Every time it leaves. For decoration that should only run while visible.
hover When the pointer enters or the element (or anything inside it) receives focus. When it is neither hovered nor holds focus. Each new hover or focus replays the effect. Moving focus between children of the element does not.
click On a click when inactive. On the next click. A toggle: first click on, second click off.
click:replay On every click. Briefly, to restart the animation. For one-shot attention effects such as shake.
time:delay Once, after delay. Never. delay is milliseconds (2000, 2000ms) or seconds (2s).
media:(query) While the media query matches (checked at load and on every change). When it stops matching. Write the query without spaces: media:(prefers-color-scheme:dark).
event:name Every time an event called name is dispatched on the element. Briefly, to restart the animation. Lets your code choose the moment without touching data-effect-active.
vt Every time a VB.swap() view transition has committed the new DOM. Briefly, to restart the animation. Pairs with data-transition="effect:class".
view-progress, view-progress:entry|exit|cover|contain Continuously: the animation follows the element's progress through the viewport (CSS animation-timeline: view()). — Entrance effects only (fade-in, slide-up, slide-in, pop, fade-in slide-up). Without timeline support it falls back to scroll.
scroll-progress Continuously: the animation follows the whole page's scroll position (animation-timeline: scroll()). — Without timeline support it falls back to scroll.

view-progress ranges

Valueanimation-rangeThe animation plays
view-progressentry 0% cover 50%From when the element starts entering until it is half way through the viewport.
view-progress:entryentry 0% entry 100%Only while the element is entering.
view-progress:exitexit 0% exit 100%Only while it is leaving.
view-progress:covercover 0% cover 100%The whole time any part of it is visible.
view-progress:containcontain 0% contain 100%Only while it is fully visible.

Scroll-driven animations run in Chromium 115+ and Safari 26+; Firefox has them behind a flag. Where they are not supported, view-progress and scroll-progress play the normal one-shot entrance when the element scrolls into view. When an element lists both scroll and view-progress, supporting browsers use the timeline: its rules come later in the stylesheet than the one-shot rules (the selectors have equal specificity).

Unknown values

A value with no registered trigger, for example a typo such as scrol, never hides the element. After the page has loaded the runtime logs one console warning per unknown name and activates the element, so the effect plays once instead of never.

Events

EventFired ondetailWhen
vb:phase-changeThe effect element (bubbles){ active: boolean }Every activation and deactivation, including the brief reset when hover, click:replay, event and vt replay an effect.
vb:effect-phase-endThe effect element (bubbles){ phase, animationName }When an entrance, exit, attention or decoration animation finishes. Also fires under reduced motion.
vb:vt-update-doneEvery [data-trigger~="vt"] element{}After VB.swap() has committed its DOM update. The vt trigger listens for it.

Styling

HookSet byMeaning
[data-effect-armed]RuntimeA registered trigger is wired and waiting. Entrance effects are hidden only while an element is armed and not yet active, so content without JavaScript, with an unknown trigger, or under reduced motion stays visible.
[data-effect-active]RuntimeThe trigger has fired. Effects publish their animation when this is present.

Use fill mode both so an element keeps its starting keyframe during a --vb-delay wait (for example inside data-stagger).

Accessibility

  • Content is never hidden for good. An entrance effect hides its element only after the runtime has wired a real trigger. Without JavaScript, with an unknown trigger, or with reduced motion the content is visible. When the script loads after the first paint, an element that will animate can show briefly before it is hidden and fades in.
  • Do not gate essential content on hover or click. An entrance effect with these triggers stays hidden until someone hovers, focuses or clicks it. hover also responds to keyboard focus, but only focusable elements (or containers with focusable children) receive focus. Prefer scroll or no trigger for content, and keep hover and click for emphasis.
  • Put click triggers on buttons. A click on a <p> or <h2> cannot come from the keyboard. Use a <button>, or wrap the effect element in one.
  • Reduced motion. With prefers-reduced-motion: reduce, or the settings-panel switch (:root[data-motion-reduced]), every effect jumps to its final state: entrances are visible at once, exits finish at once, and looping effects stop at rest. scroll, intersect and the view-progress fallback activate immediately, and view-progress does not bind the scroll timeline.
  • Looping effects (WCAG 2.2.2). A trigger such as media or intersect:toggle can start an effect that loops forever (pulse, bounce, blink). Anything that moves for more than five seconds next to other content needs a way to pause it. The reduced-motion setting is one; a visible pause control is better.
  • Scroll-linked motion (WCAG 2.3.3). view-progress and scroll-progress move content as the user scrolls, which can trigger vestibular symptoms. Keep the distance small, and the reduced-motion paths above switch it off.

Examples

Trigger independence

The same effect under four different triggers.

Click toggle and replay

view-progress

scroll-progress

Media and intersect

Events and view transitions

Custom triggers

Register your own with VB.trigger(name, handler). The handler receives the element, an activate function and the parameter after the colon, and returns a cleanup function. Elements already on the page are wired as soon as the trigger registers.

Related

↑