Back to Snippets

Swipe To Confirm Action Button JS

A track with a draggable thumb, used to make a dangerous action deliberate. Drag it to the end and the action commits. Let go early and it springs back.

Movement runs on pointer events with setPointerCapture, so the drag keeps tracking even when the cursor leaves the button or the page. Travel is clamped between zero and the track width less the thumb and its padding, which stops the thumb overshooting its own container at speed.

Release checks the position against 90 percent of the available travel. Anything short of that snaps back with a spring easing, and a success sets a completed flag that blocks further dragging. The timeout after success stands in for your own request, so replace it with the real call and clear that flag if the request fails.

327
#javascript
#css
#swipe to confirm
#button
#fintech
#payment
#secure
#drag
#ui