Back to the library

Pane — dock with a preview

Variant: Dock preview

A floating panel dragged to a workspace edge, where a dashed, tinted region shows where it would dock before it does. A drop target you can see is a decision you can still take back, and the loop takes it back once: pulled out of the zone, the preview retracts in 130ms, faster than its 180ms arrival, because a preview that lingers after the pointer has left is a lie. It grows out of its own edge and waits for the card to come to rest before appearing. On release the card hands over on one frame to the docked pane drawn at the card’s exact rectangle, which slides and unclips into the preview in 288ms and loses its lift as it joins the surface; torn back out by its header, it reverses the path in 216ms. Use it for dockable inspectors, window managers and any drag whose outcome depends on where it ends.

gesturelayoutoverlaytransitionloop

The source

A complete HTML document. Paste it into an empty .html file and it plays — no stylesheet, script, font, or image to fetch.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Pane — dock with a preview</title>
    <style>
      :root {
        /* Neutrals — fixed, never remixed. */
        --ivory: #faf9f5;
        --paper: #ffffff;
        --oat: #e3dacc;
        --slate: #141413;

        /* Knobs — the remix API. A knob exists iff declared here and used below. */
        --hue: 38.8;
        --lift: 0;
        --chroma: 1;
        --round: 1;
        --speed: 1;

        /* Accents — derived from the knobs with the family's offsets baked in,
           so one hue roll moves them together. Defaults reproduce the original hex. */
        --clay: oklch(calc(0.6724 + var(--lift)) calc(0.1308 * var(--chroma)) var(--hue));
        --clay-d: oklch(calc(0.5797 + var(--lift)) calc(0.127 * var(--chroma)) var(--hue));
        --olive: oklch(
          calc(0.6118 + var(--lift)) calc(0.0713 * var(--chroma)) calc(var(--hue) + 88.3)
        );
        --rust: oklch(
          calc(0.5408 + var(--lift)) calc(0.1357 * var(--chroma)) calc(var(--hue) - 10.3)
        );

        /* Clock — 7.2s, so 1% is 72ms. The preview arrives in 180ms and
           retracts in 130ms; the drop settles into it in 288ms, and tearing
           it back out takes 216ms. */
        --cycle: 7.2s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
        --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
        --ease-accent: cubic-bezier(0.32, 0.72, 0, 1);

        /* All geometry is in the frame's own units (cqw / cqh), so the card,
           the preview and the dock line up at every size. */
        --_r: calc(8px * var(--round));
        --_dock: 60cqw;
        --_cw: calc(100cqw - var(--_dock) - 6px);
        --_ch: 46cqh;
        --_cy: 30cqh;
        --_x0: 10cqw;
        --_x1: 54cqw;
        --_x2: 38cqw;
        --_x3: 56cqw;

        /* The card is exactly the dock's width, so the drop resolves only
           position and height: the card's offset from the dock, and its top
           and bottom measured inside the dock's 6px inset. */
        --_dx: calc(var(--_x3) - var(--_dock));
        --_top: calc(var(--_cy) - 6px);
        --_bottom: calc(100cqh - var(--_cy) - var(--_ch) - 6px);
      }

      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      body {
        min-height: 100vh;
        display: grid;
        place-items: center;
        background: var(--ivory);
        font-family:
          system-ui,
          -apple-system,
          'Segoe UI',
          Roboto,
          sans-serif;
        color: var(--slate);
      }

      .frame {
        position: relative;
        width: clamp(250px, 64vw, 380px);
        height: clamp(160px, 58vh, 220px);
        container-type: size;
        border-radius: calc(12px * var(--round));
        background: var(--paper);
        border: 1px solid color-mix(in srgb, var(--slate) 10%, transparent);
        overflow: hidden;
      }

      .page {
        position: absolute;
        inset: 0;
        padding: 12px 14px;
        display: flex;
        flex-direction: column;
        gap: 8px;
      }

      .page .title {
        font-size: 12.5px;
        font-weight: 600;
        letter-spacing: -0.01em;
        margin-bottom: 2px;
      }

      .bar {
        display: block;
        height: 7px;
        border-radius: 3.5px;
        background: color-mix(in srgb, var(--slate) 11%, transparent);
      }

      /* The preview is a promise, not the result: a tinted, dashed region
         that shows exactly where the panel would land. It grows out of the
         edge it belongs to and goes back into it, and nothing else on the
         page changes until the finger lets go. */
      .preview {
        position: absolute;
        top: 6px;
        right: 6px;
        bottom: 6px;
        left: var(--_dock);
        border-radius: var(--_r);
        background: color-mix(in srgb, var(--clay) 12%, transparent);
        border: 1.5px dashed color-mix(in srgb, var(--clay) 70%, transparent);
        transform-origin: right center;
        opacity: 0;
        transform: scaleX(0.92);
        animation: preview var(--t) infinite;
      }

      /* Edge and lift are drop-shadow filters on the unclipped parents, so
         they trace the clipped shape on every frame. Card and dock share the
         recipe exactly; the handoff between them is invisible because there
         is nothing to tell apart. */
      .card,
      .dockwrap {
        filter: drop-shadow(0 0 0.6px color-mix(in srgb, var(--slate) 38%, transparent))
          drop-shadow(0 8px 18px color-mix(in srgb, var(--slate) 14%, transparent));
      }

      .card .face,
      .dock {
        border-radius: var(--_r);
        background: var(--paper);
      }

      .card {
        position: absolute;
        left: 0;
        top: var(--_cy);
        width: var(--_cw);
        height: var(--_ch);
        transform: translateX(var(--_x0));
        animation: carry var(--t) infinite;
      }

      .card .face {
        height: 100%;
        overflow: hidden;
      }

      .head {
        display: flex;
        align-items: center;
        gap: 6px;
        height: 22px;
        padding: 0 8px;
        border-bottom: 1px solid color-mix(in srgb, var(--slate) 8%, transparent);
        font-size: 11px;
        font-weight: 600;
        color: color-mix(in srgb, var(--slate) 72%, transparent);
        white-space: nowrap;
      }

      .head::before {
        content: '';
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: var(--clay);
        flex: none;
      }

      .body {
        padding: 8px;
        display: grid;
        gap: 6px;
      }

      .body .bar {
        height: 6px;
      }

      .finger {
        position: absolute;
        left: 40%;
        top: 11px;
        width: 26px;
        height: 26px;
        margin: -13px 0 0 -13px;
        border-radius: 50%;
        background: color-mix(in srgb, var(--slate) 12%, transparent);
        opacity: 0;
        animation: finger var(--t) infinite;
      }

      /* On release the floating card hands over, on one frame, to the docked
         pane drawn at the card's exact rectangle — then it slides and
         unclips into the preview's rectangle. One shape travels from where it
         was dropped to where it was promised. Tearing it back out is the
         same path reversed, a little quicker, from the header the finger
         took hold of. */
      .dockwrap {
        position: absolute;
        top: 6px;
        right: 6px;
        bottom: 6px;
        left: var(--_dock);
        animation: settle var(--t) infinite;
      }

      .dock {
        position: absolute;
        inset: 0;
        opacity: 0;
        transform: translateX(var(--_dx));
        clip-path: inset(var(--_top) 0 var(--_bottom) 0 round var(--_r));
        animation:
          dock-open var(--t) infinite,
          dock-show var(--t) infinite;
      }

      .dock .inner {
        position: relative;
        transform: translateY(var(--_top));
        animation: dock-pin var(--t) infinite;
      }

      .dock .finger {
        animation-name: grab;
      }

      @keyframes carry {
        0%,
        8% {
          transform: translateX(var(--_x0));
          opacity: 1;
          animation-timing-function: var(--ease-in-out);
        }
        22%,
        28% {
          transform: translateX(var(--_x1));
          opacity: 1;
          animation-timing-function: var(--ease-in-out);
        }
        34%,
        38% {
          transform: translateX(var(--_x2));
          opacity: 1;
          animation-timing-function: var(--ease-in-out);
        }
        46%,
        49.9% {
          transform: translateX(var(--_x3));
          opacity: 1;
          animation-timing-function: steps(1, end);
        }
        50%,
        78.9% {
          transform: translateX(var(--_x3));
          opacity: 0;
          animation-timing-function: steps(1, end);
        }
        79% {
          transform: translateX(var(--_x3));
          opacity: 1;
          animation-timing-function: var(--ease-in-out);
        }
        92%,
        100% {
          transform: translateX(var(--_x0));
          opacity: 1;
        }
      }

      /* The preview waits until the card has come to rest over the zone, and
         leaves as soon as it is pulled out again: 180ms in, 130ms out. A
         preview that flickers with every pass of the pointer is noise; one
         that lingers after the pointer has left is a lie. */
      @keyframes preview {
        0%,
        22.5% {
          opacity: 0;
          transform: scaleX(0.92);
          animation-timing-function: var(--ease-out);
        }
        25%,
        29.5% {
          opacity: 1;
          transform: scaleX(1);
          animation-timing-function: var(--ease-out);
        }
        31.3%,
        46.5% {
          opacity: 0;
          transform: scaleX(0.92);
          animation-timing-function: var(--ease-out);
        }
        49%,
        50% {
          opacity: 1;
          transform: scaleX(1);
          animation-timing-function: var(--ease-out);
        }
        54%,
        100% {
          opacity: 0;
          transform: scaleX(1);
        }
      }

      @keyframes dock-show {
        0%,
        49.9% {
          opacity: 0;
          animation-timing-function: steps(1, end);
        }
        50%,
        78.9% {
          opacity: 1;
          animation-timing-function: steps(1, end);
        }
        79%,
        100% {
          opacity: 0;
        }
      }

      @keyframes dock-open {
        0%,
        50% {
          transform: translateX(var(--_dx));
          clip-path: inset(var(--_top) 0 var(--_bottom) 0 round var(--_r));
          animation-timing-function: var(--ease-accent);
        }
        54%,
        76% {
          transform: translateX(0);
          clip-path: inset(0 0 0 0 round var(--_r));
          animation-timing-function: var(--ease-accent);
        }
        79%,
        100% {
          transform: translateX(var(--_dx));
          clip-path: inset(var(--_top) 0 var(--_bottom) 0 round var(--_r));
        }
      }

      @keyframes dock-pin {
        0%,
        50% {
          transform: translateY(var(--_top));
          animation-timing-function: var(--ease-accent);
        }
        54%,
        76% {
          transform: translateY(0);
          animation-timing-function: var(--ease-accent);
        }
        79%,
        100% {
          transform: translateY(var(--_top));
        }
      }

      /* Docked, the pane sits in the surface and loses its lift; torn out,
         it gets it back on the same curve as the shape. */
      @keyframes settle {
        0%,
        50% {
          filter: drop-shadow(0 0 0.6px color-mix(in srgb, var(--slate) 38%, transparent))
            drop-shadow(0 8px 18px color-mix(in srgb, var(--slate) 14%, transparent));
          animation-timing-function: var(--ease-accent);
        }
        54%,
        76% {
          filter: drop-shadow(0 0 0.6px color-mix(in srgb, var(--slate) 38%, transparent))
            drop-shadow(0 0 0 transparent);
          animation-timing-function: var(--ease-accent);
        }
        79%,
        100% {
          filter: drop-shadow(0 0 0.6px color-mix(in srgb, var(--slate) 38%, transparent))
            drop-shadow(0 8px 18px color-mix(in srgb, var(--slate) 14%, transparent));
        }
      }

      @keyframes finger {
        0%,
        5% {
          opacity: 0;
          transform: scale(1.3);
          animation-timing-function: var(--ease-out);
        }
        8%,
        49% {
          opacity: 1;
          transform: scale(1);
          animation-timing-function: var(--ease-out);
        }
        52%,
        78.9% {
          opacity: 0;
          transform: scale(1.3);
          animation-timing-function: steps(1, end);
        }
        79%,
        92% {
          opacity: 1;
          transform: scale(1);
          animation-timing-function: var(--ease-out);
        }
        95%,
        100% {
          opacity: 0;
          transform: scale(1.3);
        }
      }

      /* The same finger, on the docked header: it takes hold, the pane tears
         out around it, and on the frame the card takes over it moves with
         the card. */
      @keyframes grab {
        0%,
        71% {
          opacity: 0;
          transform: scale(1.3);
          animation-timing-function: var(--ease-out);
        }
        74%,
        78.9% {
          opacity: 1;
          transform: scale(1);
          animation-timing-function: steps(1, end);
        }
        79%,
        100% {
          opacity: 0;
          transform: scale(1);
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* Nothing travels: the card is shown over the zone and crossfades
           into the docked pane, and back out again. The preview keeps its
           fade and its retract — the provisional state is the idea, and it
           survives without motion. */
        .card {
          transform: translateX(var(--_x3));
          animation-name: carry-still;
        }

        .preview {
          transform: none;
          animation-name: preview-still;
        }

        .dockwrap {
          animation: none;
          filter: drop-shadow(0 0 0.6px color-mix(in srgb, var(--slate) 38%, transparent));
        }

        .dock {
          clip-path: none;
          transform: none;
          animation: dock-still calc(var(--t) * 1.5) infinite;
        }

        .dock .inner {
          animation: none;
          transform: none;
        }

        .finger,
        .dock .finger {
          display: none;
        }

        .card,
        .preview {
          animation-duration: calc(var(--t) * 1.5);
        }

        @keyframes carry-still {
          0%,
          46% {
            opacity: 1;
            animation-timing-function: ease;
          }
          52%,
          76% {
            opacity: 0;
            animation-timing-function: ease;
          }
          82%,
          100% {
            opacity: 1;
          }
        }

        @keyframes dock-still {
          0%,
          46% {
            opacity: 0;
            animation-timing-function: ease;
          }
          52%,
          76% {
            opacity: 1;
            animation-timing-function: ease;
          }
          82%,
          100% {
            opacity: 0;
          }
        }

        @keyframes preview-still {
          0%,
          16% {
            opacity: 0;
            animation-timing-function: ease;
          }
          22%,
          28% {
            opacity: 1;
            animation-timing-function: ease;
          }
          32%,
          38% {
            opacity: 0;
            animation-timing-function: ease;
          }
          44%,
          50% {
            opacity: 1;
            animation-timing-function: ease;
          }
          54%,
          100% {
            opacity: 0;
          }
        }
      }
    </style>
  </head>
  <body>
    <div
      class="frame"
      role="img"
      aria-label="A floating inspector panel is dragged toward the right edge; a dashed preview of the docked position appears, retracts when the panel is pulled back, returns, on release the panel settles into exactly the previewed region, and is then torn back out by its header"
    >
      <div class="page">
        <span class="title">Untitled</span>
        <span class="bar" style="width: 46%"></span>
        <span class="bar" style="width: 52%"></span>
        <span class="bar" style="width: 38%"></span>
        <span class="bar" style="width: 49%"></span>
        <span class="bar" style="width: 30%"></span>
      </div>
      <span class="preview"></span>
      <div class="dockwrap">
        <div class="dock">
          <div class="inner">
            <div class="head">Inspector</div>
            <div class="body">
              <span class="bar" style="width: 80%"></span>
              <span class="bar" style="width: 60%"></span>
              <span class="bar" style="width: 70%"></span>
            </div>
            <span class="finger"></span>
          </div>
        </div>
      </div>
      <div class="card">
        <div class="face">
          <div class="head">Inspector</div>
          <div class="body">
            <span class="bar" style="width: 80%"></span>
            <span class="bar" style="width: 60%"></span>
            <span class="bar" style="width: 70%"></span>
          </div>
        </div>
        <span class="finger"></span>
      </div>
    </div>
  </body>
</html>

The variant family

Same idea, one axis moved. Compare them side by side before you commit.