Baktiyar Ablaikhan

Number Ticker

Source
Magic UI ↗
Author
Magic UI
Licence
MIT

Loading…

A number springs between 0 and 100.

Code

"use client";

import { useEffect, useState } from "react";

import { NumberTicker } from "@/lab/magicui/ui/number-ticker";

const VALUES = [100, 0];

export default function NumberTickerDemo() {
  // Alternate the target so the counter keeps ticking while the card is visible.
  const [i, setI] = useState(0);
  useEffect(() => {
    const id = setInterval(() => setI((n) => (n + 1) % VALUES.length), 3500);
    return () => clearInterval(id);
  }, []);
  return (
    <div className="@container relative flex h-full w-full items-center justify-center">
      <NumberTicker
        value={VALUES[i]}
        className="text-[clamp(4rem,16cqw,8rem)] font-medium tracking-tighter whitespace-pre-wrap text-black dark:text-white"
      />
    </div>
  );
}
Prompt

Build "Number Ticker", a text animation. What it does: A number springs between 0 and 100. Write it as a single self-contained React component in TypeScript that fills its parent (w-full h-full), styled with Tailwind CSS, using motion. Technique: the Motion library. It sits on a light background, in a 16:10 frame. Respect prefers-reduced-motion with a still state, pause work when the element is off screen, and keep it accessible. Original: https://magicui.design/docs/components/number-ticker (Magic UI, MIT).