全部效果加载与反馈

进度条

Progress Bar

任务推进时,横条的已填充部分逐步增长,也可以显示进度数值。

启动进度演示

适用场景

展示上传、下载或多步任务中可计算的完成比例。 用已处理的字节数或已完成的步骤来驱动填充长度,让用户能从进度条判断还剩多少工作。

应用示例

摄影师上传作品集压缩包时,文件行的进度条按已接收的字节数填充。走到八成时,摄影师能直接看出文件大部分已传完。

AI 提示词

给【目标任务】加上 Progress Bar。进度值绑定实际完成比例,并限制在有效范围内,随之更新可读的文字数值。使用 progress 元素或对应的进度语义。进度未知时显示不确定状态,减少动态效果模式下即刻更新。

示例代码

保存为 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;
    }

    .progress-example { display: grid; justify-items: center; gap: 12px; width: min(100%, 270px); }
    .progress-card {
      width: 100%;
      padding: 17px;
      border: 1px solid #4e456d;
      border-radius: 16px;
      background: #252139;
      color: #eee9fa;
    }
    .progress-heading {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 12px;
      font-size: 13px;
      font-weight: 600;
    }
    [data-progress-value] { color: #c6b5ff; font-variant-numeric: tabular-nums; }
    progress {
      display: block;
      appearance: none;
      width: 100%;
      height: 9px;
      overflow: hidden;
      border: 0;
      border-radius: 9px;
      background: #45405a;
      accent-color: #b9a6ff;
    }
    progress::-webkit-progress-bar { background: #45405a; }
    progress::-webkit-progress-value {
      border-radius: 9px;
      background: linear-gradient(90deg, #9075f2, #d4b6ff);
    }
    progress::-moz-progress-bar {
      border-radius: 9px;
      background: linear-gradient(90deg, #9075f2, #d4b6ff);
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="progress-example">
      <div class="progress-card">
        <div class="progress-heading">
          <label for="demo-progress">导出预览</label>
          <span aria-hidden="true" data-progress-value>38%</span>
        </div>
        <progress id="demo-progress" max="100" value="38">38%</progress>
      </div>
      <button class="demo-button" type="button" data-start>播放演示</button>
    </div>
  </main>
  <script>
    const progress = document.querySelector('progress');
    const valueLabel = document.querySelector('[data-progress-value]');
    const start = document.querySelector('[data-start]');

    function showProgress(value) {
      const percentage = value + '%';
      progress.value = value;
      progress.textContent = percentage;
      valueLabel.textContent = percentage;
    }

    let frame = 0;
    start.addEventListener('click', () => {
      cancelAnimationFrame(frame);
      if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
        showProgress(100);
        return;
      }

      showProgress(0);
      const startedAt = performance.now();
      function tick(now) {
        const completed = Math.min(100, Math.floor((now - startedAt) / 13));
        showProgress(completed);
        if (completed < 100) frame = requestAnimationFrame(tick);
      }
      frame = requestAnimationFrame(tick);
    });
  </script>
</body>
</html>

UI Skills 原创示例