数字滚轮
Rolling Numbers
不同位数的数字在各自的窗口里上下滚动,像里程表的数字轮。
适用场景
更新数据指标或积分时,让不同位数的位置保持稳定。 适合分批更新的数字,每个数位保持对齐,滚动结束后清楚呈现最终值。
应用示例
图书馆录入最新一批还书记录后,当日归还数从 129 滚动到 130。三个数位的横向位置不变,新总数在归还记录上方很容易找到。
AI 提示词
给【目标指标】做数字滚轮。每个数位使用定宽裁切窗口,值变化时位移竖排列数字。使用等宽数字,只向辅助技术读出最终值,减少动态时直接显示新数值。
示例代码
保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。
查看 HTML
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>数字滚轮</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">播放演示</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 ? "暂停演示" : "播放演示";
});
</script>
</body>
</html>UI Skills 原创示例