mouse()
functionsince 0.1requires runtimeThe pointer position in px, in viewport coordinates or relative to the element.
On this page · 9 sections+−
Syntax
mouse(x | y, viewport | local?)registry syntax: mouse(x | y [, viewport | local])
Parameters
- axis
xoryrequired - Which coordinate.
- mode
viewport(default) orlocaloptional localmeasures from the top-left corner of the element’s border box.
Return value
A length in px. 0px before the first pointer move.
Example
.pad { --x: mouse(x, local); --y: mouse(y, local);}.dot { translate: var(--x) var(--y);}mouse()Function · hover any red tokenThe pointer position in px, in viewport coordinates or relative to the element.Reference →
Resultpointer only
waiting for interaction
Behavior
- Updates at most once per frame, only for the axis that changed.
- Viewport mode is a shared source: one listener and one write per declaration, not per element.
- Inside a mutation of an
:on()rule,mouse()is a snapshot of the event:mouse(x)is its client x, andmouse(x, local)isevent(local-x), relative to the element the rule matched. There it needs a pointer or drag trigger.
Supported contexts
- Any value, and the expression of an
:on()mutation (read once, at the event).
Limitations
localdoes not update on scroll alone, and needs a layout read per element per frame.- Pointer only: provide a non-pointer alternative.
Examples
- Mouse tracker · API examples, runs the real runtime
Related
Experimental · syntax may change between minor versions