Latch — magnetic catch
Variant: Magnetic catch
An arrival that speeds up at the end, because it is captured rather than placed. A door is thrown toward a catch and let go 90px out. It coasts on an ease-out that starts at the throw's speed and runs nearly dry 12px short, which is where friction alone would have stopped it. Inside 12px the magnet's pull beats friction, and the door covers the rest in 120ms on an ease-in that picks up that last trickle of speed, five times steeper at contact, landing with 0.8px of recoil. The plot sits on the same x as the track, so the dot is always directly under the door's edge, and its height is computed from the gap, 2160 / (gap + 6)², rather than animated beside it. Pull is a quarter of friction at 30px and nine times friction at contact. Then the asymmetry: opening, the hand moves 12px while the door stays put, the hold breaks, and the door jumps to the hand in 150ms and leaves at its speed. Use it for snap-to-dock, magnetic guides and any target that should take the last few pixels off a coarse hand.
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 — magnetic catch</title>
<style>
/* Two registered gaps, in px from the catch: the door's (--_g) and the
hand's (--_h). The plot below is drawn on the same x as the track,
so the dot sits directly under the door's edge and its height is the
magnet's pull at that gap, computed from --_g — not animated beside
it. */
@property --_g {
syntax: '<number>';
inherits: true;
initial-value: 110;
}
@property --_h {
syntax: '<number>';
inherits: true;
initial-value: 110;
}
: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);
/* Clock — 5.6s: a throw that falls short, the catch, a pull free.
The door ends where it started, 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:
door var(--t) infinite,
hand 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 .shut {
animation: foot-shut var(--t) linear infinite;
}
.foot .open {
animation: foot-open var(--t) linear infinite;
}
.bench {
display: grid;
gap: 6px;
}
/* ---- the track, seen from above ---- */
.track {
position: relative;
width: 200px;
height: 40px;
}
.rail {
position: absolute;
left: 20px;
right: 10px;
top: 37px;
height: 2px;
border-radius: 1px;
background: var(--oat);
}
.catch {
position: absolute;
left: 176px;
top: 4px;
width: 14px;
height: 34px;
border-radius: 0 calc(3px * var(--round)) calc(3px * var(--round)) 0;
background: var(--oat);
}
/* The magnet face. It goes clay on contact and stays clay while it
holds — the colour is the hold, so it ends on the breakaway frame. */
.catch::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 3px;
background: var(--_muted);
animation: face var(--t) infinite;
}
.door {
position: absolute;
left: 140px;
top: 4px;
width: 36px;
height: 32px;
border-radius: calc(4px * var(--round));
background: var(--paper);
border: 1.5px solid var(--oat);
box-shadow: 0 1px 3px color-mix(in srgb, var(--slate) 14%, transparent);
transform: translateX(calc(var(--_g) * -1px));
}
.tip {
position: absolute;
left: 154px;
top: 10px;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--clay-d);
opacity: 0;
transform: translateX(calc(var(--_h) * -1px)) scale(0.6);
animation: grip var(--t) infinite;
}
/* ---- the pull, on the same x ---- */
.plot {
position: relative;
width: 200px;
height: 76px;
}
.plot svg {
display: block;
overflow: visible;
}
.axis {
fill: none;
stroke: var(--_faint);
stroke-width: 1;
}
.curve {
fill: none;
stroke: var(--oat);
stroke-width: 2;
stroke-linejoin: round;
}
.friction {
stroke: var(--_muted);
stroke-width: 1;
stroke-dasharray: 2 3;
}
.axl {
position: absolute;
font-size: 11px;
color: var(--_muted);
white-space: nowrap;
}
.axl.f {
right: 36px;
top: 0;
}
.axl.fr {
left: 20px;
top: 50px;
}
/* Pull is 2160 / (gap + 6)², so it is a quarter of the friction at 30px
and nine times the friction at contact: a magnet is not there
at all until it is the only thing there. */
.dot {
position: absolute;
left: 0;
top: 0;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--slate);
transform: translate(
calc((176 - var(--_g)) * 1px - 4px),
calc((72 - 2160 / ((var(--_g) + 6) * (var(--_g) + 6))) * 1px - 4px)
);
}
/* Closing. The hand throws from 110 to 90 and lets go; friction alone
would stop the door 12px out, so the coast is an ease-out whose
opening slope matches the throw and whose end has almost nothing
left. Inside 12px the pull beats the friction, and the door
accelerates the rest of the way — 120ms on an ease-in whose start
slope picks up that last trickle of speed, five times steeper at
contact, so it lands as a clack with 0.8px of recoil. The door is not
placed; it is captured.
Opening. The hand pulls 12px while the door does not move at all,
then the hold lets go and the door jumps the gap to the hand in
150ms, arriving at the hand's speed, and the two leave together. */
@keyframes door {
0%,
7.14% {
--_g: 110;
animation-timing-function: cubic-bezier(0.4, 0, 0.7, 0.5);
}
13.57% {
--_g: 90;
animation-timing-function: cubic-bezier(0.3, 0.285, 0.5, 0.97);
}
27.86% {
--_g: 12;
animation-timing-function: cubic-bezier(0.5, 0.03, 0.9, 0.5);
}
30% {
--_g: 0;
animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1);
}
30.54% {
--_g: 0.8;
animation-timing-function: cubic-bezier(0.45, 0, 0.55, 1);
}
31.43%,
61.61% {
--_g: 0;
animation-timing-function: cubic-bezier(0.15, 0.6, 0.5, 0.75);
}
64.29% {
--_g: 24;
animation-timing-function: cubic-bezier(0.3, 0.195, 0.4, 1);
}
76.79%,
100% {
--_g: 110;
}
}
@keyframes hand {
0%,
7.14% {
--_h: 110;
animation-timing-function: cubic-bezier(0.4, 0, 0.7, 0.5);
}
13.57%,
50% {
--_h: 90;
}
50.01%,
56.25% {
--_h: 0;
animation-timing-function: cubic-bezier(0.45, 0, 0.75, 0.5);
}
61.61% {
--_h: 12;
animation-timing-function: linear;
}
64.29% {
--_h: 24;
animation-timing-function: cubic-bezier(0.3, 0.195, 0.4, 1);
}
76.79%,
100% {
--_h: 110;
}
}
/* transform carries the hand's position on every stop, so the scale
and the travel never fight over the property. */
@keyframes grip {
0%,
3.57% {
opacity: 0;
transform: translateX(calc(var(--_h) * -1px)) scale(0.6);
animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
}
7.14%,
13.57% {
opacity: 0.4;
transform: translateX(calc(var(--_h) * -1px)) scale(1);
animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
}
16.25%,
51.79% {
opacity: 0;
transform: translateX(calc(var(--_h) * -1px)) scale(0.6);
animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
}
55.36%,
76.79% {
opacity: 0.4;
transform: translateX(calc(var(--_h) * -1px)) scale(1);
animation-timing-function: cubic-bezier(0.23, 1, 0.32, 1);
}
79.46%,
100% {
opacity: 0;
transform: translateX(calc(var(--_h) * -1px)) scale(0.6);
}
}
@keyframes face {
0%,
29.9% {
background: var(--_muted);
}
30%,
61.6% {
background: var(--clay-d);
}
61.7%,
100% {
background: var(--_muted);
}
}
@keyframes foot-shut {
0%,
32.14% {
opacity: 0;
}
34.82%,
50% {
opacity: 1;
}
52.68%,
100% {
opacity: 0;
}
}
@keyframes foot-open {
0%,
66.07% {
opacity: 0;
}
68.75%,
92.86% {
opacity: 1;
}
95.54%,
100% {
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
/* The throw goes; the hold stays. The door is parked shut against a
clay face, the dot sits at the top of the curve. */
.rig,
.tip,
.catch::before,
.foot .shut,
.foot .open {
animation: none;
}
.rig {
--_g: 0;
--_h: 0;
}
.catch::before {
background: var(--clay-d);
}
.foot .shut {
opacity: 1;
}
}
</style>
</head>
<body>
<div
class="rig"
role="img"
aria-label="A door pushed toward a magnetic catch and let go early. It coasts and slows, then in the last few pixels the magnet pulls it in faster and it closes with a click. Pulling it open, the hand moves first while the door stays held, then it breaks free all at once. A plot of magnetic pull against gap sits under the track."
>
<p class="cap">latch · magnetic catch</p>
<div class="bench">
<div class="track">
<i class="rail"></i>
<i class="catch"></i>
<i class="door"></i>
<i class="tip"></i>
</div>
<div class="plot">
<svg viewBox="0 0 200 76" width="200" height="76" aria-hidden="true">
<path class="axis" d="M20,72 L176,72 L176,2" />
<line class="friction" x1="20" y1="65.3" x2="176" y2="65.3" />
<path
class="curve"
d="M56,71.9 L76,71.8 L96,71.7 L112,71.6 L124,71.4 L134,71.1 L142,70.7 L148,70.1 L153,69.4 L157,68.5 L160,67.5 L163,66 L165,64.5 L167,62.4 L169,59.2 L170.5,55.7 L172,50.4 L173.5,42.1 L174.8,30.3 L176,12"
/>
</svg>
<span class="axl f">pull</span>
<span class="axl fr">friction</span>
<i class="dot"></i>
</div>
</div>
<p class="foot">
<span class="shut">let go early — the magnet finishes it</span>
<span class="open">opening it costs a tug</span>
</p>
</div>
</body>
</html>
The variant family
Same idea, one axis moved. Compare them side by side before you commit.