Rolling Numbers
数字滚轮
Digits travel vertically through separate windows like the reels of an odometer.
Where to use it
Animate changed metrics or points while keeping digit positions steady. Use it for discrete updates where each column stays anchored and the settled total is the value that matters.
Practical example
When a library logs its latest batch of returned books, the daily total rolls from 129 to 130. The three digit positions hold steady while the updated total stands out above the return history.
AI prompt
Make a Rolling Numbers display for [target metric]. Give each digit a fixed-width clipped window and translate a vertical reel on value changes. Use tabular numerals, expose only the final number to assistive technology, and jump directly to each new value with reduced motion.
Example code
Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.
View HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rolling Numbers</title>
<style>
:root {
color-scheme: dark;
--demo-bg: #171629;
--demo-ink: #f8f5ff;
--demo-accent: #b9a6ff;
--demo-muted: #bfbbd3;
font-family: system-ui, sans-serif;
color: var(--demo-ink);
background: var(--demo-bg);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input { font: inherit; }
.demo {
display: grid;
place-items: center;
align-content: center;
min-height: 100vh;
padding: 14px;
overflow: hidden;
background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
}
.demo-button {
border: 1px solid #ffffff3d;
border-radius: 7px;
background: #ffffff12;
color: var(--demo-ink);
padding: 6px 11px;
font-size: 12px;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--demo-accent);
outline-offset: 3px;
}
.number-reels { display: flex; gap: 5px; font: 650 29px/1.35 ui-monospace, monospace; color: #e8effd; }
.number-reels i, .number-reels div {
display: block; width: 37px; height: 1.35em; overflow: hidden;
text-align: center; font-style: normal; border: 1px solid #637589; border-radius: 6px; background: #243447;
}
.number-reels span { display: block; animation: reel 3s ease-in-out infinite; }
.number-reels div:last-child span { animation-duration: 1.5s; }
@keyframes reel {
0%, 24% { transform: translateY(0); }
34%, 57% { transform: translateY(-25%); }
67%, 90% { transform: translateY(-50%); }
100% { transform: translateY(-75%); }
}
.motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
.motion-specimen {
display: grid;
place-items: center;
width: min(100%, 295px);
height: 108px;
position: relative;
isolation: isolate;
}
.motion-example [data-motion] { animation-play-state: paused; }
.motion-example[data-playing] [data-motion] { animation-play-state: running; }
@media (prefers-reduced-motion: reduce) {
.motion-example [data-motion] { animation: none; }
.motion-example [data-loop-toggle] { display: none; }
}
</style>
</head>
<body>
<main class="demo">
<div class="motion-example">
<div class="motion-specimen" aria-hidden="true"><div class="number-reels"><i>1</i><div><span data-motion>7<br>8<br>9<br>7</span></div><div><span data-motion>6<br>7<br>8<br>6</span></div></div></div>
<button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">Play demo</button>
</div>
</main>
<script>
const example = document.querySelector('.motion-example');
const toggle = example.querySelector('[data-loop-toggle]');
toggle.addEventListener('click', () => {
const playing = example.toggleAttribute('data-playing');
toggle.textContent = playing ? "Pause demo" : "Play demo";
});
</script>
</body>
</html>Original example by UI Skills