全部效果自动播放与循环

极光背景

Aurora Background

绿色、紫色和蓝色光带在深色背景上缓慢扭曲、层叠。

播放演示,观察光带流动

适用场景

给首屏标题或登录表单铺一层极光背景。 避开表单字段布置光带最亮的区域,并给标题留出一片暗底。

应用示例

一个观星应用让多层极光从登录页两侧流过,把表单放在中间稳定的深色区域。

也叫

  • 极光 shader
  • 北极光背景

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;
    }

    .demo { position: relative; padding: 0; }
    .showcase { position: absolute; inset: 0; isolation: isolate; overflow: hidden; }
    .showcase .demo-button {
      position: absolute;
      z-index: 3;
      bottom: 10px;
      left: 50%;
      transform: translateX(-50%);
      border-radius: 999px;
      background: #101026d9;
      color: #f1efff;
      white-space: nowrap;
    }
    .showcase :is(h1, p) { margin: 0; }
    .scene-copy {
      position: absolute;
      z-index: 1;
      inset: 0;
      display: grid;
      place-content: center;
      padding: 14px;
      text-align: center;
      pointer-events: none;
    }
    .scene-copy h1 {
      font-size: clamp(25px, 8vw, 62px);
      line-height: 1;
      letter-spacing: -.045em;
    }
    .showcase [data-motion] { animation-play-state: paused; }
    .showcase[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .showcase [data-motion] { animation: none; }
      .showcase [data-loop-toggle] { display: none; }
    }

    .showcase {
      background: radial-gradient(ellipse at 50% 76%, #253f60, #11172d 52%, #091221 88%);
    }
    .aurora-curtains { position: absolute; inset: 0; overflow: hidden; }
    .curtain {
      position: absolute;
      inset: 3% -23% auto;
      height: 80%;
      border-radius: 44% 61% 37% 61% / 42% 39% 64% 62%;
      transform: rotate(-15deg) skewX(-14deg);
      filter: blur(clamp(4px, 1.8vw, 12px));
      mix-blend-mode: screen;
      animation: curtain-drift 12s ease-in-out infinite alternate;
    }
    .curtain-blue {
      background: linear-gradient(169deg, transparent 12%, #2777f96b 33%, #4f9bffcf 49%, transparent 61%);
    }
    .curtain-violet {
      top: -10%; left: -22%; right: -8%;
      background: linear-gradient(172deg, transparent 24%, #9650c781 47%, #d080d7ba 65%, transparent 70%);
      transform: rotate(12deg) skewX(18deg);
      animation-delay: -6s;
    }
    .curtain-green {
      top: 10%; left: -10%; right: -17%;
      background: linear-gradient(170deg, transparent 22%, #42bc8f6b 33%, #54eec6bf 48%, #63f7b4db 54%, transparent 65%);
      transform: rotate(-11deg) skewX(-22deg);
      animation-delay: -3s;
    }
    .aurora-ridge {
      position: absolute;
      inset: auto 0 0;
      height: 27%;
      background: linear-gradient(#151d35, #0b1122 65%);
      clip-path: polygon(0 57%, 12% 44%, 20% 61%, 33% 29%, 38% 40%, 47% 16%, 63% 60%, 73% 36%, 78% 48%, 87% 13%, 100% 52%, 100% 100%, 0 100%);
    }
    .scene-copy h1 {
      font-family: Georgia, serif;
      font-weight: 400;
      color: #f3fff8;
      text-shadow: 0 2px 13px #061c2d, 0 0 28px #072555;
    }
    @keyframes curtain-drift {
      to {
        transform: translate(9%, 6%) rotate(9deg) skewX(13deg) scale(1.15, .9);
        border-radius: 62% 37% 64% 39% / 40% 64% 35% 61%;
      }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="showcase">
      <div class="aurora-curtains" aria-hidden="true">
      <i class="curtain curtain-blue" data-motion></i>
      <i class="curtain curtain-violet" data-motion></i>
      <i class="curtain curtain-green" data-motion></i>
    </div>
    <div class="scene-copy"><h1>北境之夜</h1></div>
    <div class="aurora-ridge" aria-hidden="true"></div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
    </div>
  </main>
  <script>
    const showcase = document.querySelector('.showcase');
    const toggle = showcase.querySelector('[data-loop-toggle]');
    const preference = matchMedia('(prefers-reduced-motion: reduce)');
    let playing = false;



    function syncPlayback() {
      if (preference.matches) playing = false;
      const active = playing && !document.hidden;
      showcase.toggleAttribute('data-playing', active);
      toggle.textContent = playing ? "暂停演示" : "播放演示";
      
    }

    toggle.addEventListener('click', () => {
      playing = !playing;
      syncPlayback();
    });
    preference.addEventListener('change', syncPlayback);
    document.addEventListener('visibilitychange', syncPlayback);
  </script>
</body>
</html>

UI Skills 原创示例