SunUI
创始会员$79 终身更新,1月11日截止领取名额
免费动漫作画加载

动漫进度条

像蓄力一样的进度条:开始时出现轰鸣拟声字,填充用弹簧一段段往前冲,前缘扬起灰尘;到底时炸开冲击星、碎片与打击字,最后落定成勾与完成文字。

适合使用的场景

  • 进度一段一段到来的上传、下载与多步骤任务
  • 游戏或活动页的目标与里程碑进度条

注意事项

  • 请一段一段传入真实进度;连续的小幅增加会一直扬尘
  • 同一时刻已有别的组件落拟声字时,把 lettering 关掉
  • 开启减少动态效果时一个特效都不画,状态照常改变,不看特效也能使用

交给你的 agent 安装

一次复制就包含安装命令、使用时机、props 与设计规则。粘贴到 Claude Code、Cursor 或 Codex 即可。

用 CLI 安装

使用 shadcn CLI。源码会复制到你的项目中,每一行都由你掌控。

$ npx shadcn@latest add https://sunui.synvize.com/r/anime-progress.json

或手动安装

  1. 1. 安装依赖。
    $ npm install clsx tailwind-merge
  2. 2. 如果还没有,在 lib/utils.ts 添加 cn 辅助函数。没有用 shadcn/ui?再加上 sunui-theme.css 提供颜色变量(做法)。然后复制组件代码。
    anime-progress.tsx
    "use client";
    
    import { useEffect, useRef } from "react";
    
    import { at, burst, later, lines, onFrame, paletteOf, puff, sfx, shards, Spring, type SfxLang } from "@/components/ui/anime-fx";
    import { cn } from "@/lib/utils";
    
    export type AnimeProgressProps = {
      /** Current value, from 0 to max */
      value: number;
      max?: number;
      label: string;
      /** Shown in place of the percentage once the value reaches max */
      doneLabel?: string;
      /** Lettering language; defaults to <html lang> (Chinese pages get Chinese, others Japanese) */
      lang?: SfxLang;
      /** Show the sound-effect words (a rumble when it starts, a hit when it finishes) */
      lettering?: boolean;
      className?: string;
    };
    
    const SHELL = "border-[3px] border-foreground bg-card shadow-[4px_5px_0_color-mix(in_oklch,var(--sunui-spot,var(--primary))_38%,var(--card))]";
    
    /**
     * A progress bar that charges like an anime power-up: a rumble word when it starts, the fill surges on a spring with dust
     * kicked up at its leading edge, and at the end an impact star, chips and a hit word, settling on a check.
     * The number and aria-valuenow always show the real value; only the fill is sprung.
     */
    export function AnimeProgress({ value, max = 100, label, doneLabel = "Done", lang, lettering = true, className }: AnimeProgressProps) {
      const root = useRef<HTMLDivElement>(null);
      const bar = useRef<HTMLDivElement>(null);
      const fill = useRef<HTMLDivElement>(null);
      const spring = useRef(new Spring(0, 140, 18));
      const prev = useRef<number | null>(null);
      const ratio = Math.max(0, Math.min(1, max > 0 ? value / max : 0));
      const done = ratio >= 1;
      const pct = Math.round(ratio * 100);
    
      useEffect(() => {
        const el = bar.current;
        const s = spring.current;
        // First render: show the current value as it is, with no effects (a page that loads at 40% is not a surge)
        if (prev.current === null) {
          prev.current = ratio;
          s.x = s.to = ratio;
          if (fill.current) fill.current.style.width = `${ratio * 100}%`;
          return;
        }
        const from = prev.current;
        prev.current = ratio;
        if (!el) return;
        s.to = ratio;
        const stop = onFrame((dt) => {
          const x = Math.max(0, Math.min(1, s.step(dt)));
          if (fill.current) fill.current.style.width = `${x * 100}%`;
          if (s.still) stop();
        });
        if (ratio <= from) return stop;
        const P = paletteOf(el);
        if (from === 0 && lettering) {
          // Words sit above the label row, never on the label or the number
          const top = at(root.current ?? el, 0.5, 0);
          sfx(P, "rumble", top.x, top.y - 22, { size: 40, lang, rot: -0.06, life: 1.1 });
        }
        // Dust at the leading edge once the surge has mostly arrived
        later(140, () => {
          if (!el.isConnected) return;
          const edge = at(el, ratio, 0.5);
          puff(P, edge.x, edge.y + edge.h / 2, { size: 6, n: 4, vx: 10, vy: -16, life: 0.55 });
          lines(P, edge.x - 6, edge.y, { n: 3, dir: Math.PI, len: 22, spread: 6, life: 0.22 });
        });
        if (ratio >= 1)
          later(420, () => {
            if (!el.isConnected) return;
            const end = at(el, 1, 0.5);
            burst(P, end.x, end.y, { r: 46, spikes: 11, life: 0.4 });
            shards(P, end.x, end.y, { n: 6, speed: 160, size: 5, life: 0.6 });
            const corner = at(root.current ?? el, 1, 0);
            if (lettering) sfx(P, "impact", corner.x - 24, corner.y - 30, { size: 60, lang, life: 0.95 });
          });
        return stop;
      }, [ratio, lang, lettering]);
    
      return (
        <div ref={root} className={cn("w-full max-w-xs", className)}>
          <div className="mb-2 flex items-center justify-between gap-3 text-[13px]">
            <span className="font-bold">{label}</span>
            <span className="inline-flex items-center gap-1 tabular-nums text-muted-foreground">
              {done && (
                <svg viewBox="0 0 24 24" aria-hidden className="size-4">
                  <path d="M4 12.5l5.5 5.5L20 6" fill="none" stroke="var(--sunui-success, currentColor)" strokeWidth={3.4} strokeLinecap="round" strokeLinejoin="round" />
                </svg>
              )}
              {done ? doneLabel : `${pct}%`}
            </span>
          </div>
          <div ref={bar} role="progressbar" aria-label={label} aria-valuemin={0} aria-valuemax={100} aria-valuenow={pct} className={cn("relative h-4 overflow-hidden rounded-full p-[2px]", SHELL)}>
            <div ref={fill} className="h-full w-0 rounded-full bg-[var(--sunui-spot,var(--primary))]" />
          </div>
        </div>
      );
    }