finds.dev← search

// the find

bcherny/draggable

★ 203 · JavaScript · MIT · updated Dec 2022

High performance, fully cross browser, full featured drag and drop in a tiny (2k gzipped), dependency-free package

draggable is a dependency-free JavaScript library that makes a DOM element draggable, with grid snapping, drag handles, bounds limits and a start threshold, in about 2k gzipped. It suits someone who needs simple element dragging on a page without a framework or a drag-and-drop library, and who does not need drop targets or sortable lists.

The limit option is the most useful part. It accepts an element, per-axis ranges, a fixed value per axis, or a function that receives the current and origin coordinates, and the README's circular-radius example shows the function form doing real geometry instead of rectangle clamping. smoothDrag defaults to snapping to the grid only on drop, so the element moves freely and snaps on release. The runtime surface is small and explicit: get, set and setOption cover control after creation, and destroy removes the listeners.

The last push was in December 2022, and the tested-on list stops at Chrome 29, Firefox 23, Safari 6 and IE 8 to 10. Nothing in the README shows that touch and pointer handling has been checked against current browsers or iOS, and the to-do list admits there are no unit tests. The README says nothing about keyboard or screen-reader access, which matters if the dragged content must stay reachable without a mouse. It ships as browser globals, AMD or CommonJS, with no documented ES module export or TypeScript typings, and the examples use var, so using it in a modern build means writing your own wrapper.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →