アクティビティフィード

アバター付きの操作履歴を表示するアクティビティフィード。数秒ごとに新しい操作が一覧の先頭にスライドインし、常に最新の状態を保ちます。

#css#timeline

ライブデモ

コード

HTML
<!-- アクティビティフィード: アバター付きの操作履歴が随時先頭に追加される -->
<section class="taf">
  <div class="taf__card">
    <div class="taf__head">
      <h2 class="taf__title">最近のアクティビティ</h2>
      <span class="taf__live"><i aria-hidden="true"></i>リアルタイム</span>
    </div>

    <ol class="taf__list" aria-live="off">
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--a">田</span>
        <div class="taf__body">
          <p class="taf__text"><b>田中さん</b>が月次レポートを作成しました</p>
          <time class="taf__time">2分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--b">佐</span>
        <div class="taf__body">
          <p class="taf__text"><b>佐藤さん</b>がタスク「デザイン修正」を完了しました</p>
          <time class="taf__time">8分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--c">鈴</span>
        <div class="taf__body">
          <p class="taf__text"><b>鈴木さん</b>がコメントを追加しました</p>
          <time class="taf__time">15分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--d">山</span>
        <div class="taf__body">
          <p class="taf__text"><b>山本さん</b>が新しいメンバーを招待しました</p>
          <time class="taf__time">32分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--e">小</span>
        <div class="taf__body">
          <p class="taf__text"><b>小林さん</b>がファイルをアップロードしました</p>
          <time class="taf__time">1時間前</time>
        </div>
      </li>
    </ol>
  </div>
</section>
CSS
/* アクティビティフィード: アバター付き操作履歴。新着が先頭にスライドインする */
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #f3f4fb 0%, #e8eaf6 100%);
  color: #202336;
}

/* ルート: 全幅 */
.taf { width: 100%; display: grid; place-items: center; }

.taf__card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 18px 18px 8px;
  box-shadow: 0 24px 54px -24px rgba(30, 34, 70, .28), 0 2px 8px rgba(30, 34, 70, .05);
}

.taf__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 2px 2px 12px;
  border-bottom: 1px solid #eef0f8;
}
.taf__title { margin: 0; font-size: 15.5px; font-weight: 800; }
.taf__live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; color: #2f9e6a;
  background: #e7f8ee; padding: 5px 10px; border-radius: 999px;
  white-space: nowrap;
}
.taf__live i {
  width: 7px; height: 7px; border-radius: 50%; background: #2fbf7a;
  animation: tafPulse 1.6s ease-in-out infinite;
}

.taf__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.taf__list::-webkit-scrollbar { width: 6px; }
.taf__list::-webkit-scrollbar-thumb { background: #d7dbee; border-radius: 999px; }

.taf__item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid #f2f3fa;
}
.taf__item:last-child { border-bottom: none; }

.taf__avatar {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: #fff;
}
.taf__avatar--a { background: linear-gradient(135deg, #22c1a4, #2a8fd6); }
.taf__avatar--b { background: linear-gradient(135deg, #ff8a9c, #ff5f8f); }
.taf__avatar--c { background: linear-gradient(135deg, #ffb648, #ff8a3d); }
.taf__avatar--d { background: linear-gradient(135deg, #8f7bff, #5f5ce0); }
.taf__avatar--e { background: linear-gradient(135deg, #4fd07d, #29a862); }
.taf__avatar--f { background: linear-gradient(135deg, #5aa9ff, #3b74e0); }
.taf__avatar--g { background: linear-gradient(135deg, #ff8ad1, #d9509f); }

.taf__body { min-width: 0; }
.taf__text {
  margin: 0 0 3px;
  font-size: 13px;
  line-height: 1.55;
  color: #2b2e45;
}
.taf__text b { font-weight: 700; }
.taf__time {
  display: block;
  font-size: 11px;
  color: #9598b8;
}

/* 新着アイテムのスライドイン */
.taf__item--new { animation: tafIn .5s cubic-bezier(.22, 1, .36, 1) both; }
@keyframes tafIn {
  from { opacity: 0; transform: translateY(-10px); background: #eef7f1; }
  to   { opacity: 1; transform: translateY(0); background: transparent; }
}
@keyframes tafPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(47, 191, 122, .5); }
  50% { opacity: .55; box-shadow: 0 0 0 4px rgba(47, 191, 122, 0); }
}

@media (max-width: 420px) {
  .taf__card { padding: 14px 14px 6px; border-radius: 14px; }
  .taf__text { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .taf__live i { animation: none; }
  .taf__item--new { animation: none !important; }
}
JavaScript
// アクティビティフィード: 一定間隔で新しい操作を先頭に追加し、古い行は末尾から間引く
(() => {
  const list = document.querySelector('.taf__list');
  if (!list) return; // null安全

  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  if (reduce) return; // 動きを抑える設定では静的な初期表示のまま

  const MAX_ITEMS = 6;
  const INTERVAL_MS = 3200;

  // 追加候補(アバター文字・配色クラス・本文)を使い回してループさせる
  const POOL = [
    { avatar: '渡', cls: 'taf__avatar--f', text: '<b>渡辺さん</b>が新しいタグを追加しました' },
    { avatar: '中', cls: 'taf__avatar--a', text: '<b>中村さん</b>がプロジェクトを公開しました' },
    { avatar: '高', cls: 'taf__avatar--g', text: '<b>高橋さん</b>が承認リクエストを送信しました' },
    { avatar: '伊', cls: 'taf__avatar--b', text: '<b>伊藤さん</b>がダッシュボードを更新しました' },
    { avatar: '加', cls: 'taf__avatar--c', text: '<b>加藤さん</b>がメンバーにメンションしました' },
    { avatar: '木', cls: 'taf__avatar--d', text: '<b>木村さん</b>がコメントに返信しました' },
  ];
  let poolIndex = 0;

  const addItem = () => {
    const d = POOL[poolIndex % POOL.length];
    poolIndex++;

    const li = document.createElement('li');
    li.className = 'taf__item taf__item--new';
    li.innerHTML =
      `<span class="taf__avatar ${d.cls}">${d.avatar}</span>` +
      `<div class="taf__body"><p class="taf__text">${d.text}</p><time class="taf__time">たった今</time></div>`;
    list.prepend(li);

    // 表示件数の上限を超えたら末尾を間引く
    while (list.children.length > MAX_ITEMS) {
      list.removeChild(list.lastElementChild);
    }
  };

  const timer = setInterval(addItem, INTERVAL_MS);

  // プレビューを離れた際に備えたクリーンアップ(同一ドキュメント内でのみ有効)
  window.addEventListener('pagehide', () => clearInterval(timer));
})();

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

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

# 追加してほしい効果
アクティビティフィード(タイムライン & 404)
アバター付きの操作履歴を表示するアクティビティフィード。数秒ごとに新しい操作が一覧の先頭にスライドインし、常に最新の状態を保ちます。

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

# 参考実装(この見た目・挙動を再現してください)
【HTML】
<!-- アクティビティフィード: アバター付きの操作履歴が随時先頭に追加される -->
<section class="taf">
  <div class="taf__card">
    <div class="taf__head">
      <h2 class="taf__title">最近のアクティビティ</h2>
      <span class="taf__live"><i aria-hidden="true"></i>リアルタイム</span>
    </div>

    <ol class="taf__list" aria-live="off">
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--a">田</span>
        <div class="taf__body">
          <p class="taf__text"><b>田中さん</b>が月次レポートを作成しました</p>
          <time class="taf__time">2分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--b">佐</span>
        <div class="taf__body">
          <p class="taf__text"><b>佐藤さん</b>がタスク「デザイン修正」を完了しました</p>
          <time class="taf__time">8分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--c">鈴</span>
        <div class="taf__body">
          <p class="taf__text"><b>鈴木さん</b>がコメントを追加しました</p>
          <time class="taf__time">15分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--d">山</span>
        <div class="taf__body">
          <p class="taf__text"><b>山本さん</b>が新しいメンバーを招待しました</p>
          <time class="taf__time">32分前</time>
        </div>
      </li>
      <li class="taf__item">
        <span class="taf__avatar taf__avatar--e">小</span>
        <div class="taf__body">
          <p class="taf__text"><b>小林さん</b>がファイルをアップロードしました</p>
          <time class="taf__time">1時間前</time>
        </div>
      </li>
    </ol>
  </div>
</section>

【CSS】
/* アクティビティフィード: アバター付き操作履歴。新着が先頭にスライドインする */
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #f3f4fb 0%, #e8eaf6 100%);
  color: #202336;
}

/* ルート: 全幅 */
.taf { width: 100%; display: grid; place-items: center; }

.taf__card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 18px 18px 8px;
  box-shadow: 0 24px 54px -24px rgba(30, 34, 70, .28), 0 2px 8px rgba(30, 34, 70, .05);
}

.taf__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 2px 2px 12px;
  border-bottom: 1px solid #eef0f8;
}
.taf__title { margin: 0; font-size: 15.5px; font-weight: 800; }
.taf__live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; color: #2f9e6a;
  background: #e7f8ee; padding: 5px 10px; border-radius: 999px;
  white-space: nowrap;
}
.taf__live i {
  width: 7px; height: 7px; border-radius: 50%; background: #2fbf7a;
  animation: tafPulse 1.6s ease-in-out infinite;
}

.taf__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.taf__list::-webkit-scrollbar { width: 6px; }
.taf__list::-webkit-scrollbar-thumb { background: #d7dbee; border-radius: 999px; }

.taf__item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid #f2f3fa;
}
.taf__item:last-child { border-bottom: none; }

.taf__avatar {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: #fff;
}
.taf__avatar--a { background: linear-gradient(135deg, #22c1a4, #2a8fd6); }
.taf__avatar--b { background: linear-gradient(135deg, #ff8a9c, #ff5f8f); }
.taf__avatar--c { background: linear-gradient(135deg, #ffb648, #ff8a3d); }
.taf__avatar--d { background: linear-gradient(135deg, #8f7bff, #5f5ce0); }
.taf__avatar--e { background: linear-gradient(135deg, #4fd07d, #29a862); }
.taf__avatar--f { background: linear-gradient(135deg, #5aa9ff, #3b74e0); }
.taf__avatar--g { background: linear-gradient(135deg, #ff8ad1, #d9509f); }

.taf__body { min-width: 0; }
.taf__text {
  margin: 0 0 3px;
  font-size: 13px;
  line-height: 1.55;
  color: #2b2e45;
}
.taf__text b { font-weight: 700; }
.taf__time {
  display: block;
  font-size: 11px;
  color: #9598b8;
}

/* 新着アイテムのスライドイン */
.taf__item--new { animation: tafIn .5s cubic-bezier(.22, 1, .36, 1) both; }
@keyframes tafIn {
  from { opacity: 0; transform: translateY(-10px); background: #eef7f1; }
  to   { opacity: 1; transform: translateY(0); background: transparent; }
}
@keyframes tafPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(47, 191, 122, .5); }
  50% { opacity: .55; box-shadow: 0 0 0 4px rgba(47, 191, 122, 0); }
}

@media (max-width: 420px) {
  .taf__card { padding: 14px 14px 6px; border-radius: 14px; }
  .taf__text { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .taf__live i { animation: none; }
  .taf__item--new { animation: none !important; }
}

【JavaScript】
// アクティビティフィード: 一定間隔で新しい操作を先頭に追加し、古い行は末尾から間引く
(() => {
  const list = document.querySelector('.taf__list');
  if (!list) return; // null安全

  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  if (reduce) return; // 動きを抑える設定では静的な初期表示のまま

  const MAX_ITEMS = 6;
  const INTERVAL_MS = 3200;

  // 追加候補(アバター文字・配色クラス・本文)を使い回してループさせる
  const POOL = [
    { avatar: '渡', cls: 'taf__avatar--f', text: '<b>渡辺さん</b>が新しいタグを追加しました' },
    { avatar: '中', cls: 'taf__avatar--a', text: '<b>中村さん</b>がプロジェクトを公開しました' },
    { avatar: '高', cls: 'taf__avatar--g', text: '<b>高橋さん</b>が承認リクエストを送信しました' },
    { avatar: '伊', cls: 'taf__avatar--b', text: '<b>伊藤さん</b>がダッシュボードを更新しました' },
    { avatar: '加', cls: 'taf__avatar--c', text: '<b>加藤さん</b>がメンバーにメンションしました' },
    { avatar: '木', cls: 'taf__avatar--d', text: '<b>木村さん</b>がコメントに返信しました' },
  ];
  let poolIndex = 0;

  const addItem = () => {
    const d = POOL[poolIndex % POOL.length];
    poolIndex++;

    const li = document.createElement('li');
    li.className = 'taf__item taf__item--new';
    li.innerHTML =
      `<span class="taf__avatar ${d.cls}">${d.avatar}</span>` +
      `<div class="taf__body"><p class="taf__text">${d.text}</p><time class="taf__time">たった今</time></div>`;
    list.prepend(li);

    // 表示件数の上限を超えたら末尾を間引く
    while (list.children.length > MAX_ITEMS) {
      list.removeChild(list.lastElementChild);
    }
  };

  const timer = setInterval(addItem, INTERVAL_MS);

  // プレビューを離れた際に備えたクリーンアップ(同一ドキュメント内でのみ有効)
  window.addEventListener('pagehide', () => clearInterval(timer));
})();

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

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