Skip to content

Roll

Text that rolls as it changes: digits turn like an odometer's and keep their places, letters and icons roll over.

v1.1.0MITGitHubnpm
npm install @cesarvenzac/roll
€8A price
997A count
9:57A clock
SavingA word
CopyAn icon
MonA day
Look
Direction
FadeScaleBlurSlow
A price, a count, a clock, a word, an icon and a day, each rolling to its next value, the day letter by letter. Pick a look, a direction and effects; Slow stretches the springs to watch a turn.

Roll draws text that rolls as it changes. Give it the value as you'd write it, formatted however you like, and it works out the rest: a number's digits keep their places and turn as an odometer's do, forward as it counts up and back as it counts down; signs, letters and icons roll over. At rest it's plain text.

Use

import { Roll } from "@cesarvenzac/roll/react";

<Roll value={price} />; // "€8", then "€6.67"

Or without React:

import { roll } from "@cesarvenzac/roll";

const price = roll(element, "€8");
price.set("€6.67");

Playground

€8
Kind of value
Look
Direction
Effects
FadeScaleBlurMotion
Stagger
Numbers
TrendCount
0.6 s
0.00
The code for what's shown
import { Roll } from "@cesarvenzac/roll/react";

<Roll value={price} />
Every option, beside the code that makes what's shown. Type a value, or let it step through its kind.

What it does

  • Digits keep their places. The units stay the units: 9 becoming 10 turns the 9 to 0 as a 1 rolls in on its left, 9:59 becoming 10:00 keeps its colon, and a fraction is read from its mark.
  • The way the number went. Each digit turns forward as it counts up and back as it counts down, never the long way round, read from the numbers themselves, signs and fractions included.
  • Everything else rolls over. Signs, a word's letters in their places, icons as one; with reels, letters turn through the alphabet, all one way, as a split-flap board's.
  • Any look, any way. A flat strip by default; with look, a slot machine's drum or a turning cube in perspective, a circle rolling like a wheel, a square tipping over its edge or a swap in place; with direction, up, down, left or right; and with effects, faded, scaled or blurred as it goes.
  • Counts, tints, tells. With count a number passes every value on its way, with trend it flashes green going up and red going down, and settled, onSettle and groups say when it's landed.
  • Anywhere. React's <Roll>, roll() for any element, <roll-text> for any page, a Svelte action and a Vue directive, none of which needs anything else installed.
  • Springs that carry on. Sent somewhere else mid-way, a digit goes on from where it is at the speed it has, and comes home as quickly as a fresh turn.
  • Plain text at rest. One text node, as crisp as any text, its width the font's, read once by assistive tech; under reduced motion a change fades in where it stands.
  • Small and plain. TypeScript with no dependencies, about 5 kB, every roller on a page changing in one batch with one layout.

Docs