Skip to content

Looks and effects

A flat strip, a drum, a cube, a rolling circle, a tipping square or a swap in place, in any direction, faded, scaled or blurred as it goes.

@cesarvenzac/rollv1.1.0

A symbol slides on a flat strip unless you say otherwise. look changes how it turns, direction where it goes and effects what's laid over it:

<Roll value={price} look="drum" />
<Roll value={time} look="circle" direction="right" />
<Roll value={label} look="swap" effects={["scale", "blur"]} />

Looks

  • slide: a flat strip, symbols a line apart. The default.
  • drum: symbols round a drum, 30° apart, seen in perspective and shaded as they turn away, as a slot machine's.
  • cube: each symbol a face of a box, a quarter turn a step.
  • circle: each symbol rolls along without slipping, on a wheel half a line across.
  • square: each symbol tips over its leading corner, a quarter turn a step.
  • swap: in place, the old symbol giving way to the next: a crossfade, unless effects say more.

A face of a drum or a cube shows only while it faces you: a symbol a whole turn round, as a letter turning through the alphabet passes, never shows over the one there.

Directions

direction is where a symbol goes as the value turns forward: up (the default: it leaves upward and the next comes up from below), down, left or right. Counting down runs a turn the other way. A circle rolling right turns clockwise, rolling left the other way.

Going across, what leaves stays inside its own cell, fading at its sides, never passing over the characters beside it.

Effects

effects lays any of these over any look, together or alone:

  • fade: out as it leaves and in as it comes, as far as it has gone.
  • scale: down to 60% as it leaves and back as it comes, never to nothing, which reads as a glitch.
  • blur: to 0.08em as it leaves, sharp as it lands.
  • motion: blurred by how fast it goes rather than how far, up to 0.12em: a long spin smears, then lands sharp. With count, it's an odometer's blur.
<Roll value={visitors} count effects={["motion"]} />
<Roll value={status} look="swap" effects={["scale", "blur"]} />

How they're drawn

Each look is geometry the browser works out every frame from one sprung value, through CSS's sin(), cos() and round(): as smooth as the spring, with no script running frame by frame. A flat look moves in the page as the text beside it does, so it lands on the text's own pixels; drum and cube are drawn in 3D, on layers of their own, and land within half a device pixel of it.

Looks and effects need a registered CSS property and CSS's trigonometry and rounding: Chrome 125, Safari 16.4, Firefox 128. Elsewhere every look slides up, without effects. Under reduced motion none of them moves: In the page says what happens instead.