Back to the library

Latch — push-push

Variant: Push-push

One gesture that means two things, with the state kept by the mechanism and not the hand. Shown in section beside the heart-shaped cam a pen click actually uses. Press once: 360ms to the bottom, past both rests, and on release the spring drives the button back up until the pin drops into the notch and stops it dead. Both releases are ease-ins: the spring pushes hardest at the bottom, so the plunger is still gaining speed when it is stopped, because a catch is a collision, not an arrival. Press again: the pin leaves the notch along the other flank, and the release runs the full travel to the top stop with a half-unit bounce. Both presses overtravel on purpose. The extra depth is where the cam changes track, and without it a push-push has nowhere to choose between in and out. The cam is drawn point-up so the pin travels the way the button does. The held rest sits nearly eight units below the out rest, so the button shows its own state from across the room, and the clay band on its face is only a second witness. Use it for sticky modes — record, hold, pin — where a toggle would be too easy to knock and a press-and-hold too much to ask.

physicscontrolgesturediagramloop

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>Latch — push-push</title>
    <style>
      /* One registered number, the plunger's travel in cam units (0 out,
         12 bottomed, 7.86 caught). The plunger, its spring, and the pin's
         height on the cam are all functions of it, and the pin's
         offset-distance runs on the same keyframe stops and the same
         curves, so the cam and the button cannot drift a frame apart. */
      @property --_k {
        syntax: '<number>';
        inherits: true;
        initial-value: 0;
      }

      :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)
        );

        --_muted: color-mix(in srgb, var(--slate) 52%, transparent);
        --_faint: color-mix(in srgb, var(--slate) 22%, transparent);
        --_groove: color-mix(in srgb, var(--oat) 70%, transparent);

        /* Clock — 5.6s: press, catch, hold, press, release. It ends where it
           began, so the loop needs no reset. */
        --cycle: 5.6s;
        --t: calc(var(--cycle) / var(--speed));
      }

      * {
        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);
      }

      .rig {
        display: grid;
        gap: clamp(8px, 3vh, 14px);
        justify-items: center;
        animation: travel var(--t) infinite;
      }

      .cap,
      .foot {
        font-size: 11px;
        letter-spacing: 0.04em;
        color: var(--_muted);
      }

      .foot {
        display: grid;
        justify-items: center;
      }

      .foot span {
        grid-area: 1 / 1;
        opacity: 0;
        white-space: nowrap;
      }

      .foot .once {
        animation: foot-once var(--t) linear infinite;
      }

      .foot .again {
        animation: foot-again var(--t) linear infinite;
      }

      .row {
        display: flex;
        align-items: center;
        gap: clamp(18px, 6vw, 32px);
      }

      /* ---- the button, in section ---- */

      .button {
        position: relative;
        width: 96px;
        height: 114px;
      }

      /* Rest marks at the two heights the plunger can stop at. Reading the
         state off the button's own height is the point of a push-push. */
      .mark {
        position: absolute;
        left: 0;
        width: 42px;
        display: flex;
        align-items: center;
        gap: 4px;
        font-size: 11px;
        color: var(--_muted);
        transform: translateY(-50%);
      }

      .mark::after {
        content: '';
        flex: 1;
        height: 1px;
        background: var(--_faint);
      }

      .mark.out {
        top: 22px;
      }

      .mark.held {
        top: 37.7px;
      }

      .plunger {
        position: absolute;
        left: 42px;
        top: 22px;
        width: 36px;
        height: 44px;
        transform: translateY(calc(var(--_k) * 2px));
      }

      .plunger .face {
        position: absolute;
        inset: 0;
        border-radius: calc(5px * var(--round)) calc(5px * var(--round)) 0 0;
        background: var(--paper);
        border: 1.5px solid var(--oat);
        border-bottom: 0;
        overflow: hidden;
      }

      /* A clay band on the face while it is held — the state, worn on the
         part that holds it. */
      .plunger .band {
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        height: 4px;
        background: var(--clay-d);
        transform: scaleY(0);
        transform-origin: top;
        animation: band var(--t) infinite;
      }

      .tip {
        position: absolute;
        left: 8px;
        top: -20px;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: var(--clay-d);
        opacity: 0;
        transform: scale(0.6);
        animation: grip var(--t) infinite;
      }

      .panel {
        position: absolute;
        top: 50px;
        height: 7px;
        background: var(--oat);
      }

      .panel.l {
        left: 32px;
        width: 10px;
        border-radius: calc(2px * var(--round)) 0 0 calc(2px * var(--round));
      }

      .panel.r {
        left: 78px;
        width: 10px;
        border-radius: 0 calc(2px * var(--round)) calc(2px * var(--round)) 0;
      }

      .spring {
        position: absolute;
        left: 50px;
        bottom: 4px;
        width: 20px;
        height: 44px;
        transform-origin: bottom;
        transform: scaleY(calc((44 - var(--_k) * 2) / 44));
      }

      .spring svg {
        display: block;
        width: 100%;
        height: 100%;
        overflow: visible;
      }

      .spring path {
        fill: none;
        stroke: var(--_muted);
        stroke-width: 1.5;
        stroke-linejoin: round;
        vector-effect: non-scaling-stroke;
      }

      .floor {
        position: absolute;
        left: 36px;
        bottom: 0;
        width: 48px;
        height: 4px;
        border-radius: calc(2px * var(--round));
        background: var(--oat);
      }

      /* ---- the cam ---- */

      .cam {
        position: relative;
        width: 80px;
        height: 80px;
      }

      .cam svg {
        display: block;
        overflow: visible;
      }

      .groove {
        fill: none;
        stroke: var(--_groove);
        stroke-width: 8;
        stroke-linejoin: round;
      }

      .line {
        fill: none;
        stroke: var(--oat);
        stroke-width: 1;
        stroke-linejoin: round;
      }

      .catch {
        fill: none;
        stroke: var(--clay-d);
        stroke-width: 1.5;
        opacity: 0;
        transform-box: fill-box;
        transform-origin: center;
        animation: catch var(--t) infinite;
      }

      /* The cam is drawn point-up so the pin moves the way the button does:
         down the left flank on the first press, up into the notch when the
         spring returns, down the right flank on the second, and home up the
         long side. Its height on the cam is the plunger's
         travel, segment for segment, because each straight leg changes
         height linearly with distance along it. */
      .pin {
        position: absolute;
        left: 0;
        top: 0;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--slate);
        offset-path: path('M40,8 L16,66 L40,46 L64,66 Z');
        offset-rotate: 0deg;
        offset-anchor: center;
        offset-distance: 0%;
        animation: pin var(--t) infinite;
      }

      /* Press one: 360ms to the bottom on the hand's in-out curve, a 140ms
         hold, then the spring takes it back up 4.1 units and the notch stops
         it dead. Both releases are ease-ins: the spring pushes hardest at
         the bottom and the plunger is still gaining speed when it is
         stopped, because a catch is a collision, not an arrival. Press two is shorter, 280ms, since
         it starts from the held depth, and its release runs the full 12
         units in 260ms to the top stop with a half-unit bounce. Both presses
         overtravel past either rest: the extra depth is where the cam
         switches tracks, and it is why one gesture can mean two things. */
      @keyframes travel {
        0%,
        7.14% {
          --_k: 0;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        13.57%,
        16.07% {
          --_k: 12;
          animation-timing-function: cubic-bezier(0.4, 0, 0.9, 0.6);
        }
        18.57%,
        46.43% {
          --_k: 7.862;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        51.43%,
        53.57% {
          --_k: 12;
          animation-timing-function: cubic-bezier(0.4, 0, 0.9, 0.6);
        }
        58.21% {
          --_k: 0;
          animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1);
        }
        58.93% {
          --_k: 0.5;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        59.82%,
        100% {
          --_k: 0;
        }
      }

      @keyframes pin {
        0%,
        7.14% {
          offset-distance: 0%;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        13.57%,
        16.07% {
          offset-distance: 33.38%;
          animation-timing-function: cubic-bezier(0.4, 0, 0.9, 0.6);
        }
        18.57%,
        46.43% {
          offset-distance: 50%;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        51.43%,
        53.57% {
          offset-distance: 66.62%;
          animation-timing-function: cubic-bezier(0.4, 0, 0.9, 0.6);
        }
        58.21% {
          offset-distance: 100%;
          animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1);
        }
        58.93% {
          offset-distance: 98.61%;
          animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
        }
        59.82%,
        100% {
          offset-distance: 100%;
        }
      }

      /* The finger leaves on the release frame, faster than the spring can
         follow it: what the plunger does next is the mechanism's answer. */
      @keyframes grip {
        0%,
        3.57% {
          opacity: 0;
          transform: scale(0.6);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        7.14%,
        16.07% {
          opacity: 0.4;
          transform: scale(1);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        18.21%,
        42.86% {
          opacity: 0;
          transform: translateY(-6px) scale(0.6);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        46.43%,
        53.57% {
          opacity: 0.4;
          transform: scale(1);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        55.71%,
        100% {
          opacity: 0;
          transform: translateY(-6px) scale(0.6);
        }
      }

      /* The notch rings once on the catch frame and stays lit while it
         holds; it lets go the moment the second press lifts the pin out. */
      @keyframes catch {
        0%,
        18.5% {
          opacity: 0;
          transform: scale(1.8);
        }
        18.57% {
          opacity: 1;
          transform: scale(1.8);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        21.43%,
        46.43% {
          opacity: 1;
          transform: scale(1);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        48.21%,
        100% {
          opacity: 0;
          transform: scale(1);
        }
      }

      @keyframes band {
        0%,
        18.5% {
          transform: scaleY(0);
        }
        18.57% {
          transform: scaleY(0);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        21.43%,
        53.57% {
          transform: scaleY(1);
          animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
        }
        55.36%,
        100% {
          transform: scaleY(0);
        }
      }

      @keyframes foot-once {
        0%,
        20.54% {
          opacity: 0;
        }
        23.21%,
        44.64% {
          opacity: 1;
        }
        47.32%,
        100% {
          opacity: 0;
        }
      }

      @keyframes foot-again {
        0%,
        59.82% {
          opacity: 0;
        }
        62.5%,
        92.86% {
          opacity: 1;
        }
        95.54%,
        100% {
          opacity: 0;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* The travel goes; the held state stays. The plunger sits at the
           held mark with its band on, the pin rests in the notch. */
        .rig,
        .pin,
        .tip,
        .plunger .band,
        .catch,
        .foot .once,
        .foot .again {
          animation: none;
        }

        .rig {
          --_k: 7.862;
        }

        .pin {
          offset-distance: 50%;
        }

        .plunger .band {
          transform: scaleY(1);
        }

        .catch {
          opacity: 1;
        }

        .foot .once {
          opacity: 1;
        }
      }
    </style>
  </head>
  <body>
    <div
      class="rig"
      role="img"
      aria-label="A push-push button in section beside its heart-shaped cam. The first press goes past the bottom and, on release, the pin catches in the notch so the button stays held lower than its rest. The second press frees the pin and the button springs back out."
    >
      <p class="cap">latch · push-push</p>
      <div class="row">
        <div class="button">
          <span class="mark out">out</span>
          <span class="mark held">held</span>
          <div class="spring">
            <svg viewBox="0 0 20 44" preserveAspectRatio="none" aria-hidden="true">
              <path d="M10,0 L2,4 L18,11 L2,18 L18,25 L2,32 L18,39 L10,44" />
            </svg>
          </div>
          <div class="plunger">
            <div class="face"><i class="band"></i></div>
            <i class="tip"></i>
          </div>
          <i class="panel l"></i>
          <i class="panel r"></i>
          <i class="floor"></i>
        </div>
        <div class="cam">
          <svg viewBox="0 0 80 80" width="80" height="80" aria-hidden="true">
            <path class="groove" d="M40,8 L16,66 L40,46 L64,66 Z" />
            <path class="line" d="M40,8 L16,66 L40,46 L64,66 Z" />
            <circle class="catch" cx="40" cy="46" r="7" />
          </svg>
          <i class="pin"></i>
        </div>
      </div>
      <p class="foot">
        <span class="once">pressed once — it stays in</span>
        <span class="again">pressed again — it lets go</span>
      </p>
    </div>
  </body>
</html>

The variant family

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