All effectsScroll & reveal

Scroll Elastic Wave Divider

滚动弹性波浪分隔线

A curved boundary bends with scroll progress and settles with a short spring response.

Scroll inside the example

Where to use it

Connect two colored editorial sections with a fluid transition. Use it between sections that already differ in color. Keep the spring shallow and allow it to settle before the next transition.

Practical example

On a marine science page, the curved divider between a sand-colored shoreline chapter and a blue tide-pool chapter bends as visitors scroll past it. It bounces softly into its resting shape.

AI prompt

Add Scroll Elastic Wave Divider to [target]. Map scroll progress to the paired handles of a cubic Bézier. Dampen the control value with a spring, redraw the seam in one canvas layer, and stop frames when the spring settles. Keep the controls keyboard accessible and provide a reduced-motion state.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Scroll Elastic Wave Divider</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;
    }

    .scroll-port {
      --frame: clamp(112px, 75vh, 242px);
      --p: 0;
      width: min(100%, 290px); height: var(--frame);
      overflow-y:auto; overflow-x:hidden; scroll-behavior:auto;
      overscroll-behavior:contain; scrollbar-width:thin;
      scrollbar-color:#a79bd5 #20223d; border-radius:12px;
      border:1px solid #a79bd567; background:#20233c; color:#f5f2ff;
    }
    .scroll-port:focus-visible { outline-offset: 3px; }
    .scroll-track { position:relative; min-height:calc(var(--frame) + 235px); }
    .scroll-pin { position:sticky; top:0; height:var(--frame); overflow:hidden; }
    .scroll-pin .tag { position:absolute; z-index:4; left:8px; bottom:9px; font-size:10px; color:#ecfcff; padding:4px 6px; background:#17152ce8; border-radius:4px; }
    .scroll-panel { min-height:62px; padding:9px; border:1px solid #adb2e345; border-radius:8px; background:linear-gradient(120deg,#314861,#3e346a); }


    .wave-canvas { width:100%; height:100%; display:block; background:linear-gradient(155deg,#2b395e,#29496a); }


    @media (prefers-reduced-motion: reduce) {
      .lab, .lab *, .lab::before, .lab::after, .lab *::before, .lab *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
      }
    }
  </style>
</head>
<body>
  <main class="demo">
    <div class="lab scroll-port" role="region" tabindex="0" aria-label="Scroll to bend the divider"><div class="scroll-track"><div class="scroll-pin"><canvas class="wave-canvas" width="280" height="152" aria-hidden="true"></canvas><span class="tag" aria-hidden="true">Elastic seam</span></div></div></div>
  </main>
  <script>
    const port = document.querySelector('.scroll-port');
    const reduced = matchMedia('(prefers-reduced-motion: reduce)');
    const listeners = [];
    let scheduled = 0;
    function sample() {
      const max = Math.max(1,port.scrollHeight - port.clientHeight);
      return Math.max(0,Math.min(1,port.scrollTop / max));
    }
    function update() {
      scheduled = 0;
      const progress = sample();
      port.style.setProperty('--p', progress.toFixed(4));
      for (const callback of listeners) callback(progress);
    }
    function schedule() { if (!scheduled) scheduled = requestAnimationFrame(update); }
    function onScroll(callback) { listeners.push(callback); callback(sample()); }
    port.addEventListener('scroll', schedule, {passive:true});
    new ResizeObserver(schedule).observe(port);
    reduced.addEventListener('change', schedule);
    update();

    const canvas = port.querySelector('canvas');
    const ctx = canvas.getContext('2d');
    let target = 0;
    let position = 0;
    let velocity = 0;
    let frame = 0;
    function paint() {
      if (!ctx) return;
      const wave = Math.sin(position * Math.PI * 2 + .25) * 32;
      const center = 65 + 18 * position;
      const fill = ctx.createLinearGradient(0,70,280,152);
      fill.addColorStop(0,'#955dd3');
      fill.addColorStop(1,'#477e97');
      ctx.clearRect(0,0,280,152);
      ctx.beginPath();
      ctx.moveTo(0,center);
      ctx.bezierCurveTo(68,center + wave, 205,center - wave, 280,center);
      ctx.lineTo(280,152);
      ctx.lineTo(0,152);
      ctx.closePath();
      ctx.fillStyle = fill;
      ctx.fill();
      ctx.beginPath();
      ctx.moveTo(0,center);
      ctx.bezierCurveTo(68,center + wave, 205,center - wave, 280,center);
      ctx.strokeStyle = '#f0ddff';
      ctx.lineWidth = 2;
      ctx.stroke();
    }
    function animate() {
      frame = 0;
      velocity = (velocity + (target - position)*.13)*.70;
      position += velocity;
      paint();
      if (Math.abs(target-position) + Math.abs(velocity) > .001) frame = requestAnimationFrame(animate);
    }
    onScroll((progress) => {
      target = reduced.matches ? 0 : progress;
      if (reduced.matches) { cancelAnimationFrame(frame); frame = 0; position = 0; velocity = 0; paint(); }
      else if (!frame) frame = requestAnimationFrame(animate);
    });
  </script>
</body>
</html>

Original example by UI Skills

Further examples