進捗バー

0%から100%まで一定速度で満ちる決定的な進捗バー。進捗のしきい値ごとに色が変化し、縞模様が流れ続けて完了までの見通しを伝えます。

#css#js#progress

ライブデモ

コード

HTML
<!-- 進捗バー: 0→100%を一定速度で描画する決定的な進捗バー。しきい値ごとに色が変わる -->
<div class="stage">
  <div class="panel">
    <div class="panel__head">
      <span class="panel__label" id="slpLabel">読み込みを開始しています…</span>
      <span class="panel__pct" id="slpPct">0%</span>
    </div>
    <div class="track" id="slpTrack" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-label="処理の進捗">
      <div class="track__fill" id="slpFill"></div>
    </div>
    <p class="panel__note" id="slpNote">残り時間を計算しています</p>
  </div>
</div>
CSS
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 15% 15%, #2d2f73 0%, transparent 48%),
    radial-gradient(circle at 88% 82%, #1e2a52 0%, transparent 50%),
    #0c0d1c;
  color: #f4f5ff;
}

.stage {
  width: 100%;
  display: grid;
  place-items: center;
}

.panel {
  width: min(360px, 100%);
  padding: 28px 26px 24px;
  border-radius: 20px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel__label {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: rgba(244, 245, 255, 0.85);
}

.panel__pct {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.track {
  position: relative;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.track__fill {
  --fill-color: #f6b93b;
  position: relative;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background-color: var(--fill-color);
  transition: width 0.12s linear, background-color 0.6s ease;
  overflow: hidden;
}

.track__fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.35) 0 14px,
    transparent 14px 28px
  );
  background-size: 40px 40px;
  mix-blend-mode: overlay;
  animation: slp-stripes 0.9s linear infinite;
}

@keyframes slp-stripes {
  from { background-position: 0 0; }
  to   { background-position: 40px 0; }
}

.panel__note {
  margin: 12px 0 0;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: rgba(244, 245, 255, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  .track__fill { transition: background-color 0.6s ease; }
  .track__fill::after { animation: none; }
}

@media (max-width: 380px) {
  .panel { padding: 22px 18px 18px; }
}
JavaScript
// 進捗バー: requestAnimationFrameで一定速度(線形)に0→100%を描画し、しきい値で色とラベルを切り替える
(() => {
  const track = document.getElementById('slpTrack');
  const fill  = document.getElementById('slpFill');
  const pctEl = document.getElementById('slpPct');
  const label = document.getElementById('slpLabel');
  const note  = document.getElementById('slpNote');
  if (!track || !fill || !pctEl) return; // null安全

  const DURATION = 4200; // ms、0→100%にかかる時間
  const HOLD = 1200;     // 完了後にとどまる時間

  // 進捗の段階ごとに色とメッセージを変える(先着優先)
  const STAGES = [
    { max: 34,  color: '#f6b93b', label: '読み込みを開始しています…', note: 'サーバーへ接続しています' },
    { max: 67,  color: '#38bdf8', label: 'データを検証しています…',   note: '整合性を確認しています' },
    { max: 100, color: '#34d399', label: 'もうすぐ完了します…',       note: '仕上げの処理を実行しています' },
  ];

  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

  function stageFor(p) {
    for (const s of STAGES) if (p <= s.max) return s;
    return STAGES[STAGES.length - 1];
  }

  function render(p) {
    const stage = stageFor(p);
    fill.style.width = p + '%';
    fill.style.setProperty('--fill-color', stage.color);
    pctEl.textContent = p + '%';
    track.setAttribute('aria-valuenow', String(p));
    if (p >= 100) {
      if (label) label.textContent = '完了しました';
      if (note) note.textContent = 'すべての処理が終わりました';
    } else {
      if (label) label.textContent = stage.label;
      if (note) note.textContent = stage.note;
    }
  }

  function loop() {
    let startTime = null;

    function frame(now) {
      if (startTime === null) startTime = now;
      const elapsed = now - startTime;
      const p = Math.min(100, Math.round((elapsed / DURATION) * 100));
      render(p);

      if (p < 100) {
        requestAnimationFrame(frame);
      } else {
        setTimeout(() => {
          render(0);
          requestAnimationFrame(frame2);
        }, HOLD);
      }
    }

    // 2周目以降も同じ挙動でループさせるための再入口
    function frame2(now) {
      startTime = null;
      frame(now);
    }

    requestAnimationFrame(frame);
  }

  if (reduce) {
    // モーション抑制時は数秒おきの離散更新のみに留める
    let p = 0;
    render(0);
    setInterval(() => {
      p = p >= 100 ? 0 : Math.min(100, p + 20);
      render(p);
    }, 900);
    return;
  }

  loop();
})();

🤖 AIエージェント用プロンプト

このままコピーしてAIに貼り付け「追加する場所」だけ書き換えればOK
あなたは熟練のフロントエンドエンジニアです。私のWebサイトに「進捗バー」の効果を追加してください。

# 追加してほしい効果
進捗バー(カレンダー & ステップ)
0%から100%まで一定速度で満ちる決定的な進捗バー。進捗のしきい値ごとに色が変化し、縞模様が流れ続けて完了までの見通しを伝えます。

# 追加する場所
👉【ここに対象箇所を記入:例「トップのヒーローセクション」「お問い合わせボタン」「記事カードの一覧」など】

# 参考実装(この見た目・挙動を再現してください)
【HTML】
<!-- 進捗バー: 0→100%を一定速度で描画する決定的な進捗バー。しきい値ごとに色が変わる -->
<div class="stage">
  <div class="panel">
    <div class="panel__head">
      <span class="panel__label" id="slpLabel">読み込みを開始しています…</span>
      <span class="panel__pct" id="slpPct">0%</span>
    </div>
    <div class="track" id="slpTrack" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" aria-label="処理の進捗">
      <div class="track__fill" id="slpFill"></div>
    </div>
    <p class="panel__note" id="slpNote">残り時間を計算しています</p>
  </div>
</div>

【CSS】
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 15% 15%, #2d2f73 0%, transparent 48%),
    radial-gradient(circle at 88% 82%, #1e2a52 0%, transparent 50%),
    #0c0d1c;
  color: #f4f5ff;
}

.stage {
  width: 100%;
  display: grid;
  place-items: center;
}

.panel {
  width: min(360px, 100%);
  padding: 28px 26px 24px;
  border-radius: 20px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel__label {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: rgba(244, 245, 255, 0.85);
}

.panel__pct {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.track {
  position: relative;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.track__fill {
  --fill-color: #f6b93b;
  position: relative;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background-color: var(--fill-color);
  transition: width 0.12s linear, background-color 0.6s ease;
  overflow: hidden;
}

.track__fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.35) 0 14px,
    transparent 14px 28px
  );
  background-size: 40px 40px;
  mix-blend-mode: overlay;
  animation: slp-stripes 0.9s linear infinite;
}

@keyframes slp-stripes {
  from { background-position: 0 0; }
  to   { background-position: 40px 0; }
}

.panel__note {
  margin: 12px 0 0;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: rgba(244, 245, 255, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  .track__fill { transition: background-color 0.6s ease; }
  .track__fill::after { animation: none; }
}

@media (max-width: 380px) {
  .panel { padding: 22px 18px 18px; }
}

【JavaScript】
// 進捗バー: requestAnimationFrameで一定速度(線形)に0→100%を描画し、しきい値で色とラベルを切り替える
(() => {
  const track = document.getElementById('slpTrack');
  const fill  = document.getElementById('slpFill');
  const pctEl = document.getElementById('slpPct');
  const label = document.getElementById('slpLabel');
  const note  = document.getElementById('slpNote');
  if (!track || !fill || !pctEl) return; // null安全

  const DURATION = 4200; // ms、0→100%にかかる時間
  const HOLD = 1200;     // 完了後にとどまる時間

  // 進捗の段階ごとに色とメッセージを変える(先着優先)
  const STAGES = [
    { max: 34,  color: '#f6b93b', label: '読み込みを開始しています…', note: 'サーバーへ接続しています' },
    { max: 67,  color: '#38bdf8', label: 'データを検証しています…',   note: '整合性を確認しています' },
    { max: 100, color: '#34d399', label: 'もうすぐ完了します…',       note: '仕上げの処理を実行しています' },
  ];

  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

  function stageFor(p) {
    for (const s of STAGES) if (p <= s.max) return s;
    return STAGES[STAGES.length - 1];
  }

  function render(p) {
    const stage = stageFor(p);
    fill.style.width = p + '%';
    fill.style.setProperty('--fill-color', stage.color);
    pctEl.textContent = p + '%';
    track.setAttribute('aria-valuenow', String(p));
    if (p >= 100) {
      if (label) label.textContent = '完了しました';
      if (note) note.textContent = 'すべての処理が終わりました';
    } else {
      if (label) label.textContent = stage.label;
      if (note) note.textContent = stage.note;
    }
  }

  function loop() {
    let startTime = null;

    function frame(now) {
      if (startTime === null) startTime = now;
      const elapsed = now - startTime;
      const p = Math.min(100, Math.round((elapsed / DURATION) * 100));
      render(p);

      if (p < 100) {
        requestAnimationFrame(frame);
      } else {
        setTimeout(() => {
          render(0);
          requestAnimationFrame(frame2);
        }, HOLD);
      }
    }

    // 2周目以降も同じ挙動でループさせるための再入口
    function frame2(now) {
      startTime = null;
      frame(now);
    }

    requestAnimationFrame(frame);
  }

  if (reduce) {
    // モーション抑制時は数秒おきの離散更新のみに留める
    let p = 0;
    render(0);
    setInterval(() => {
      p = p >= 100 ? 0 : Math.min(100, p + 20);
      render(p);
    }, 900);
    return;
  }

  loop();
})();

# 外部ライブラリ
なし(追加ライブラリ不要)

# 守ってほしいこと
- 既存のHTML構造・レイアウト・デザインを壊さないこと。必要に応じてクラス名・色・サイズを私のサイトに合わせて調整してよい。
- クラス名やidが既存と衝突しないよう、必要なら接頭辞で名前空間を分けること。
- レスポンシブ対応と prefers-reduced-motion への配慮を入れること。
- 私のサイトのフレームワーク(React / Vue / 素のHTML など)に合わせて実装すること。不明な場合は素のHTML/CSS/JSで提示し、組み込み手順も説明すること。
- 変更後の確認手順も簡潔に教えてください。