Documents v0.10.0 · previews run the real runtime · experimental features are marked exp

:on(every())

rulesince 0.10experimentalrequires runtime

Runs every interval while the rule is active, the first time after a first delay.

On this page · 8 sections+

Syntax

<selector>:on(every(<interval> [, <first delay>])) {  --<state>: increment(1);}
:on()Rule · hover any red tokenAn event rule: when the event happens on the matched element (or inside it, for bubbling events), the rule’s state mutations run. The cascade picks one winning mutation per state, per trigger and per element.Reference →

registry syntax: :on(every(interval [, first delay])) { --state: … }

Parameters

intervalms or srequired
Minimum 20 ms; smaller values are raised, with a diagnostic.
first delayms or soptional
Default: one interval.

Effect

No value. Each run is a transaction, like an event.

Example

hold.cssreactive
.counter { --held: state(false); --count: state(0); }.counter button:on(pointerdown) { --held: set(true); }.counter button:on(pointerup | pointerleave | pointercancel) { --held: set(false); }.counter:when(--held):on(every(80ms, 400ms)) { --count: increment(1); }
state()Function · hover any red tokenMakes each matching element the owner of an independent state with an initial value.Reference →

Behavior

  • No drift: each run is planned from the previous planned time. Missed runs are skipped, not replayed.
  • Paused while the page is hidden; on return, the next run is one interval later.
  • Timers due together share one setTimeout and one pass. Two active rules with the same trigger share one timer, and the cascade picks per state.
  • Ticks are not a clock: use time() for elapsed time.

Supported contexts

  • Unconditional rules and rules with :when(), classes and attributes in the selector.

Limitations

  • No modifiers, and event() is not available.
  • Rules cannot depend on :hover, :focus, :checked and other states the runtime cannot follow, and cannot be nested in a rule with a state condition.
Experimental · syntax may change between minor versions