# draggy

> Make element draggable

Latest version **2.0.5** (published 2024-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install draggy
pnpm add draggy
yarn add draggy
bun add draggy
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2024-10-18 |
| First published | 2014-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 48.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Dmitry Iv |
| Maintainers | dfcreative, dy |
| Keywords | draggable, drag-n-drop, interact, draggy, drag, drop, drag-and-drop |

## Links

- npm: https://www.npmjs.com/package/draggy
- Repository: https://github.com/dy/draggy
- Issues: https://github.com/dy/draggy/issues
- npm.io page: https://npm.io/package/draggy

## Dependencies (6)

- [emmy](https://npm.io/package/emmy.md) ^7.1.1
- [mucss](https://npm.io/package/mucss.md) ^1.0
- [to-px](https://npm.io/package/to-px.md) ^1.1.0
- [mutype](https://npm.io/package/mutype.md) ^0.3.9
- [define-state](https://npm.io/package/define-state.md) ^1.0.0
- [get-client-xy](https://npm.io/package/get-client-xy.md) ^1.0.1

## Recent versions

- 2.0.5 (latest) — 2024-10-18
- 2.0.4 — 2024-10-18
- 2.0.3 — 2024-10-18
- 2.0.2 — 2024-10-18
- 2.0.1 — 2024-10-18
- 2.0.0 — 2024-10-18
- 1.6.6 — 2016-09-01
- 1.6.5 — 2016-07-19
- 1.6.4 — 2016-07-06
- 1.6.3 — 2016-05-04
- 1.6.2 — 2016-05-04
- 1.6.1 — 2016-01-10
- 1.6.0 — 2016-01-10
- 1.5.2 — 2016-01-10
- 1.5.1 — 2016-01-10
- … 55 more at https://npm.io/package/draggy/versions

## README

<h1>
<img src="https://cdn.rawgit.com/dy/draggy/design/logo.png"/>

Draggy

<a href="/license"><img src="https://img.shields.io/npm/l/draggy.svg"/></a>
</h1>


Make any element draggable. [Demo](https://dy.github.io/draggy).


[![npm install draggy](https://nodei.co/npm/draggy.png?mini=true)](https://npmjs.org/package/draggy)

```js
import Draggable from 'draggy';

//make an element draggable
var el = document.querySelector('.my-element');
var draggy = new Draggable(el, {
	release: true,
	sniper: false,
	axis: 'x'
});

//bind event handler
draggy.on('drag', function () {
	// ...
});
```


## Options

| Parameter | Default | Description |
|---|:---:|---|
| `axis` | `null` | Restrict movement by axis: `'x'`, `'y'` or `null`. |
| `pin` | `[0,0, selfWidth, selfHeight]` | Defines a smaller area within the draggable element that stays within movement limits. Useful to restrict movement based on an inner shape rather than the full element. |
| `precision` | `1` | Round position to that extent, in pixels. |
| `css3` | `true` | Use `position` vs `translate3d` to place element. The first is more precise and reliable, the second is faster. |
| `release` | `false` | Continue movement when user releases drag. |
| `repeat` | `false` | Loop movement by one of axis: `'x'`, `'y'` or `'both'`. |
| `sniper` | `true` | Slow down movement by pressing Ctrl/Cmd. |
| `threshold` | `0` | A movement threshold required to start drag - whether an array, number or function. |
| `within` | `document` | Restrict movement within the container. Pass `'parent'` to use parent node. |
| `handle` | `self.element` | Use element or selector as a handle for drag. Clicking outside the handle is ignored. |
| `cancel` | `undefined` | Ignore dragging started on the elements matching the selector. |
| `droppable` | `undefined` | Selector, element or list of elements to detect droppable areas. For each drop element will be invoked `drop`, `dragover` and `dragout` events. |


## Events

| Name | Description |
|---|---|
| `dragstart` | Drag started. Called both on element/controller. |
| `threshold` | Entered threshold mode. Called on controller. |
| `drag` | Drag iteration. Called both on element/controller. |
| `track` | Track movement. Called on controller. |
| `release` | User released drag. Called on controller. |
| `dragend` | Drag has completely finished. Called both on element/controller. |
| `dragover` |  Called on self and on drop target. |
| `dragout` |  Called on self and on drop target. |
| `drop` |  Called on self and on drop target. |



## What draggy is not

* It doesn’t do ghost move, as it is not draggable behavior and can be implemented externally.
* It doesn’t do mouse hiding on drag, as it can be done via callbacks.
* It doesn’t init itself automatically - it's up to you to decide when to create/init draggable.
* It doesn’t polyfill native draggable, as it targets to complete simple task of visual placement of element.

## Alternatives

* [interactjs](https://www.npmjs.com/package/interactjs)
* [@shopify/draggable](https://www.npmjs.com/package/@shopify/draggable)
* [draggabilly](https://www.npmjs.com/package/draggabilly)

## License

MIT

---
_Source: https://npm.io/package/draggy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
