Grab it anywhere and it stays under the pointer, because it moves by the pointer’s delta and not by its position. Push past an edge and it resists instead of stopping dead. Let go fast and it glides. Then tab to it and do all of the same with the arrow keys, which is the half that is usually missing.
the inset ring is the bound — push past it
let sx = 0, sy = 0, ox = 0, oy = 0; /* start pointer, start offset */
grip.addEventListener("pointerdown", e => {
grip.setPointerCapture(e.pointerId); /* 1. never lose the release */
grip.classList.remove("glide"); /* no transition while held */
grip.classList.add("held");
sx = e.clientX; sy = e.clientY; ox = x; oy = y;
});
grip.addEventListener("pointermove", e => {
if (!grip.hasPointerCapture(e.pointerId)) return;
move(ox + (e.clientX - sx), oy + (e.clientY - sy)); /* 2. DELTA, not position */
});
grip.addEventListener("pointerup", e => {
grip.classList.remove("held");
grip.classList.add("glide"); /* 3. transition only now */
settle(velocity);
});
/* 4. past the bound it still moves, less and less */
const band = (d, size) => d / (1 + Math.abs(d) / size);touch-action:none on the handle, not
on the container. translate rather than left, so no frame of a drag
touches layout. And the glide class is added on release and removed on the next grab,
which is how a drag is direct and a release is animated using the same element.