全部效果加载与反馈

堆叠提示条

Toast Stack

多条简短状态提示叠放出现,可逐条关闭。

连点保存,让多条通知堆叠

适用场景

不中断当前任务地反馈多项后台操作。 每条通知点明完成了什么,短时间触发多项操作时,用户扫一眼就能分清。

应用示例

在图片编辑器里连续保存方图和横幅裁切结果,两条通知分别显示对应文件名。用户可以关掉第一条,另一条仍留在通知堆里。

AI 提示词

用堆叠提示条显示【状态事件】。最多同时展示三条,每条可单独关闭,用非打断式动态区域播报新消息并保留当前焦点。

示例代码

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

    .example { width: min(100%, 228px); position: relative; display: grid; gap: 10px; }
    .panel { background: #292240; border: 1px solid #675785; border-radius: 11px; padding: 10px; }
    .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
    .label { margin: 0; font-size: 13px; font-weight: 650; }
    .detail, .caption { margin: 0; color: #d7cbea; font-size: 11px; line-height: 1.35; }
    .caption { text-align: center; }
    .control { border: 1px solid #8874ae; background: #392e57; border-radius: 7px; padding: 5px 9px; min-height: 32px; color: #f6efff; cursor: pointer; font-size: 11px; font-weight: 650; }
    .control:hover { background: #514174; }
    .control.primary { color: #261b3f; background: #d1bfff; border-color: #e3d8ff; }
    .control.primary:hover { background: #e3d8ff; }
    .control:disabled { opacity: .55; cursor: default; }
    .field { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid #875fa8; border-radius: 6px; color: #f6efff; background: #1e1732; font-size: 12px; }
    .field::placeholder { color: #c2abd8; }
    [hidden] { display: none !important; }

    .toast-stack { display: grid; gap: 4px; min-height: 30px; margin: 0; padding: 0; list-style: none; }
    .toast-stack .panel { padding: 3px 6px 3px 9px; animation: toast-in .2s ease both; }
    .toast-stack .control { min-height: 23px; padding: 1px 6px; }
    @keyframes toast-in { from { opacity: 0; transform: translateY(5px); } }

    @media (prefers-reduced-motion: reduce) {
      .example *, .example *::before, .example *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="example"><div class="actions"><button class="control primary" type="button" data-add>保存副本</button></div><ol class="toast-stack" aria-label="通知记录" aria-live="polite"></ol></div>
  </main>
  <script>
    const list = document.querySelector('.toast-stack');
    const add = document.querySelector('[data-add]');
    let copies = 0;
    add.addEventListener('click', () => {
      if (list.childElementCount === 3) list.firstElementChild.remove();
      copies += 1;
      const notification = document.createElement('li');
      notification.className = 'panel row';
      const message = document.createElement('span');
      message.className = 'detail';
      message.textContent = "已保存副本" + ' ' + copies;
      const dismiss = document.createElement('button');
      dismiss.className = 'control';
      dismiss.type = 'button';
      dismiss.textContent = '×';
      dismiss.setAttribute('aria-label', "关闭通知");
      dismiss.addEventListener('click', () => { notification.remove(); add.focus(); });
      notification.append(message, dismiss);
      list.append(notification);
    });
  </script>
</body>
</html>

UI Skills 原创示例