全部效果滚动与入场

滚动分镜

Pinned Scroll Chapters

文字向上滚动时,画面固定在视口内。下一章越过视口中线,画面随之切换。

滚动文字区,或聚焦后按方向键

适用场景

适合分章节讲述专题、产品原理或图解流程。 每章准备一幅能独立传达信息的画面,等相关段落进入阅读区域时再切换。固定区要给文字留出足够空间。

应用示例

塑料瓶回收专题里,分拣、清洗和熔融三段说明从右侧滚过时,左侧示意图始终留在屏幕上。切到下一章,画面就换成对应的处理设备。

AI 提示词

为【目标区块】加入滚动分镜。用 position: sticky 固定视觉栏,让语义化章节按正常文档流滚动。章节越过视口中线时更新当前章节,交叉淡入对应插图。保留原生滚动和键盘导航。减少动态效果模式下直接切换画面。

示例代码

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

    .chapter-view {
      --scene-height: clamp(144px, 57vh, 255px);
      display: grid;
      grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
      align-items: start;
      position: relative;
      overflow: auto;
      overscroll-behavior: contain;
      scrollbar-width: thin;
      scrollbar-color: #629399 #153033;
      width: min(100%, 490px);
      height: var(--scene-height);
      border-radius: 14px;
      background: #11242a;
      box-shadow: 0 0 0 1px #638a8d80;
    }
    .chapter-stage {
      position: sticky;
      top: 0;
      height: var(--scene-height);
      overflow: hidden;
      background: #10383d;
    }
    .scene { position: absolute; inset: 0; overflow: hidden; opacity: 0; transition: opacity 320ms ease; }
    .chapter-stage[data-active-chapter="0"] .surface,
    .chapter-stage[data-active-chapter="1"] .twilight,
    .chapter-stage[data-active-chapter="2"] .midnight { opacity: 1; }
    .scene i, .scene b { position: absolute; display: block; }
    .surface { background: linear-gradient(167deg, #8affdd 0%, #39afad 32%, #10515b 80%); }
    .surface i { top: 12%; left: 15%; width: 43%; aspect-ratio: 1; border-radius: 50%; background: #fff7b6; box-shadow: 0 0 30px #f8ffd5b0; }
    .surface b { inset: auto -8% 0; height: 42%; background: linear-gradient(145deg, #168c86, #0b373e); clip-path: polygon(0 55%, 15% 28%, 29% 33%, 46% 11%, 67% 30%, 80% 12%, 100% 5%, 100% 100%, 0% 100%); }
    .twilight { background: radial-gradient(ellipse at 70% 0%, #47739a, #173e5b 55%, #152737 89%); }
    .twilight i { top: 26%; left: 45%; width: 39%; height: 27%; transform: rotate(-13deg); border: 2px solid #95e8ff; border-radius: 53% 64% 45% 46%; background: linear-gradient(#6dbfd4a8, #8ccbf529); box-shadow: 0 0 17px #7df4ff67; }
    .twilight b { top: 49%; left: 53%; width: 25%; height: 29%; border-radius: 0 0 40% 40%; background: repeating-linear-gradient(82deg, transparent 0 5px, #b7e9ff85 5px 6px, transparent 6px 11px); transform: skewX(-11deg); }
    .midnight { background: radial-gradient(ellipse at 45% 49%, #303055, #151936 55%, #121928 88%); }
    .midnight i { top: 27%; left: 15%; width: 72%; height: 43%; transform: rotate(-13deg); border-radius: 65% 21% 58% 42%; background: radial-gradient(circle at 77% 31%, #f9ffc4 0 4%, transparent 6%), linear-gradient(160deg, #8f80f1, #4d3bae 44%, #313284 80%); box-shadow: 0 0 18px #7a7eed8f; }
    .midnight b { top: 22%; left: 65%; width: 10%; aspect-ratio: 1; border-radius: 50%; background: #fff2ae; box-shadow: 0 0 14px 6px #d9fdeb70; }
    .scene-index { position: absolute; bottom: 7px; left: 8px; padding: 3px 6px; border-radius: 4px; background: #111e31df; color: white; font-size: 11px; font-variant-numeric: tabular-nums; }
    .chapter { display: grid; align-content: center; gap: 5px; min-height: var(--scene-height); padding: 10px; border-inline-start: 2px solid transparent; background: #11242a; transition: border-color 320ms ease; }
    .chapter[aria-current] { border-inline-start-color: #81f0c8; }
    .chapter h2 { margin: 0; color: #e8f8f0; font-size: clamp(12px, 3vw, 18px); line-height: 1.15; }
    .chapter p { margin: 0; color: #bad8d6; font-size: clamp(10px, 2.4vw, 14px); line-height: 1.35; }
    @media (prefers-reduced-motion: reduce) {
      .scene, .chapter { transition: none; }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="chapter-view" role="region" tabindex="0" data-testid="effect-demo-chapter-scroll" aria-label="滚动浏览海洋分层">
      <div class="chapter-stage" aria-hidden="true" data-active-chapter="0">
        <div class="scene surface"><i></i><b></b></div>
        <div class="scene twilight"><i></i><b></b></div>
        <div class="scene midnight"><i></i><b></b></div>
        <span class="scene-index">1 / 3</span>
      </div>
      <div class="chapter-list">
        <section class="chapter" aria-current="step">
          <h2>日照层</h2>
          <p>阳光照进浅海,鱼群在礁石间穿行。</p>
        </section>
        <section class="chapter">
          <h2>微光层</h2>
          <p>光线逐渐变暗,水温随深度下降。</p>
        </section>
        <section class="chapter">
          <h2>无光层</h2>
          <p>阳光无法抵达,有些生物会自己发光。</p>
        </section>
      </div>
    </div>
  </main>
  <script>
    const scrollView = document.querySelector('.chapter-view');
    const stage = document.querySelector('.chapter-stage');
    const counter = stage.querySelector('.scene-index');
    const chapters = Array.from(document.querySelectorAll('.chapter'));
    let active = 0;
    let scheduled = false;

    function updateChapter() {
      scheduled = false;
      const midpoint = scrollView.scrollTop + scrollView.clientHeight / 2;
      let next = active;
      for (let index = 0; index < chapters.length; index++) {
        if (chapters[index].offsetTop > midpoint) break;
        next = index;
      }
      if (next === active) return;
      chapters[active].removeAttribute('aria-current');
      chapters[next].setAttribute('aria-current', 'step');
      stage.dataset.activeChapter = String(next);
      counter.textContent = (next + 1) + ' / ' + chapters.length;
      active = next;
    }

    function queueUpdate() {
      if (scheduled) return;
      scheduled = true;
      requestAnimationFrame(updateChapter);
    }

    scrollView.addEventListener('scroll', queueUpdate, { passive: true });
    addEventListener('resize', queueUpdate);
    queueUpdate();
  </script>
</body>
</html>

UI Skills 原创示例

相关参考