FIG-001/ DRAG

a slider knob on a plain element.

drag() makes the knob draggable on x and keeps it inside its track. Reset animates the knob home with animate(); both work on the same x value, so the next drag starts from wherever the knob is.

  • axis: 'x' locks the knob to one axis and sets touch-action: pan-y, so a vertical swipe on a phone still scrolls the page.
  • constraints: track keeps the knob inside the track element. Release it with some speed and it glides, then settles against the edge.
  • drag() and animate() share the knob's x, so Reset springs it home and the next drag continues from where it is.
↩ all examples
constraints · track mode · live running source
// slider knob value · 0
drag(knob, { axis: 'x', constraints: track })
category · drag
sheet · sheet 01 / 02
⟳ to re-run
FIG-002/ HEADLESS

a dial driven by a motion value.

Motion 14.10 lets drag() write into x/y motion values instead of moving the element. The dial stays where it is; a horizontal drag turns it, and a flick spins it with momentum.

  • drag(dial, { axis: 'x', x }) writes the drag into x, not the dial's own transform, so the dial never moves.
  • x.on('change') turns the value into the dial's rotate. Release with some speed and momentum keeps writing to x, so the dial spins down.
↩ all examples
x · motionValue(0) mode · live running source
// rotary dial rotate · 0°
drag(dial, { axis: 'x', x })
category · headless
sheet · sheet 02 / 02
⟳ to re-run

Vanilla drag()