Skip to content

Animated Digits

Roll the digits of a focus timer as it counts down, with the time in the format of the locale. An sv-text-flow in the time slot gets each new time and animates the digits that change.

Reduced Motion

Your system is set to reduce motion, so the animations shown on this page will not play for you.

Code

The following example assumes that you have imported the components and set up the theme.

Animated Digits
<div class="timer-animated">
8 collapsed lines
<sv-timer duration="25m">
<sv-text-flow class="timer-animated-digits" slot="time"></sv-text-flow>
</sv-timer>
<div class="timer-animated-actions">
<button type="button" class="btn btn-primary timer-animated-start">Start</button>
<button type="button" class="btn timer-animated-reset">Reset</button>
</div>
</div>
<script type="application/x-typescript" module>
10 collapsed lines
const timer = document.querySelector<Timer>(".timer-animated sv-timer")!;
const startButton = document.querySelector<HTMLButtonElement>(".timer-animated-start")!;
const resetButton = document.querySelector<HTMLButtonElement>(".timer-animated-reset")!;
startButton.addEventListener("click", () => (timer.running ? timer.pause() : timer.start()));
resetButton.addEventListener("click", () => timer.reset());
timer.addEventListener("runningchange", () => {
startButton.textContent = timer.running ? "Pause" : "Start";
});
</script>
<style>
17 collapsed lines
.timer-animated {
display: grid;
gap: 1em;
place-content: center;
justify-items: center;
}
.timer-animated-digits::part(text) {
font-size: 3rem;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.timer-animated-actions {
display: flex;
gap: 0.5em;
}
</style>