全部效果自动播放与循环

流动网格渐变

Animated Mesh Gradient

几片重叠的色光各自缓慢移动,在交界处融合。

播放或暂停演示

适用场景

给简洁的首屏或播放封面加上流动背景。 阅读区域背后的颜色移动宜慢,文字所在位置可加一层稳定的底色来维持对比。

应用示例

音效素材库给氛围音合集的封面加上缓慢融合的蓝色、淡紫和琥珀色光斑。背景逐渐变换,曲目名和播放控件放在固定的深色面板上。

AI 提示词

给【目标区域】制作流动网格渐变。叠加三层较大的径向渐变,用 transform 独立移动图层,并裁切边缘。文字放在稳定的对比层上,提供暂停和减少动态时的静态渐变。

示例代码

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

    .mesh { width: min(100%, 235px); height: 96px; border-radius: 14px; overflow: hidden; position: relative; background: #152751; border: 1px solid #ffffff2e; }
    .mesh i {
      width: 73%; aspect-ratio: 1; position: absolute; top: -40%; left: -16%;
      background: radial-gradient(circle, #9ac8ff, #7467ed 37%, transparent 72%);
      animation: drift-mesh 5s ease-in-out infinite alternate;
    }
    .mesh i:nth-child(2) {
      top: -20%; left: 27%; background: radial-gradient(circle, #f8bbdf, #d568ae 37%, transparent 72%);
      animation-direction: alternate-reverse; animation-duration: 7s;
    }
    .mesh i:nth-child(3) {
      top: 17%; left: 55%; background: radial-gradient(circle, #a0f1dd, #588fcf 37%, transparent 72%);
      animation-duration: 8s;
    }
    @keyframes drift-mesh { to { transform: translate(32%, -13%) scale(1.18); } }

    .motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
    .motion-specimen {
      display: grid;
      place-items: center;
      width: min(100%, 295px);
      height: 108px;
      position: relative;
      isolation: isolate;
    }
    .motion-example [data-motion] { animation-play-state: paused; }
    .motion-example[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .motion-example [data-motion] { animation: none; }
      .motion-example [data-loop-toggle] { display: none; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="motion-example">
      <div class="motion-specimen" aria-hidden="true"><div class="mesh"><i data-motion></i><i data-motion></i><i data-motion></i></div></div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
    </div>
  </main>
  <script>
    const example = document.querySelector('.motion-example');
    const toggle = example.querySelector('[data-loop-toggle]');

    toggle.addEventListener('click', () => {
      const playing = example.toggleAttribute('data-playing');
      toggle.textContent = playing ? "暂停演示" : "播放演示";
    });
  </script>
</body>
</html>

UI Skills 原创示例