# v-dragged

> Vue directive plugin for advanced drag event detection.

Latest version **0.0.5** (published 2017-10-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install v-dragged
pnpm add v-dragged
yarn add v-dragged
bun add v-dragged
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2017-10-22 |
| First published | 2017-10-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 86 |
| Author | zhanziyang |
| Maintainers | zhanziyang |
| Keywords | drag, vue, event, directive, touch, moving, mouse, vue plugin, javascript, web, front-end, lightweight, mobile |

## Links

- npm: https://www.npmjs.com/package/v-dragged
- Repository: https://github.com/zhanziyang/v-dragged
- Homepage: https://zhanziyang.github.io/v-dragged/
- Issues: https://github.com/zhanziyang/v-dragged/issues
- npm.io page: https://npm.io/package/v-dragged

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.0.5 (latest) — 2017-10-22
- 0.0.4 — 2017-10-22
- 0.0.3 — 2017-10-22
- 0.0.2 — 2017-10-09
- 0.0.1 — 2017-10-09

## README

# v-dragged
> Vue directive plugin for drag event detection.

**NOTE:** This directive listens to the mouse/touch behavior and set a handler for when a drag action is detected. This is different from setting `draggable` on element in that you need to move the element yourself according to the information *v-dragged* provides.

## Install

```bash
npm install --save v-dragged
```
```js
import Vue from 'vue'
import VDragged from 'v-dragged'

Vue.use(VDragged) 
```

## Example

```html
<div v-dragged="onDragged"></div>
```
```js
{
  // ...other options omitted

  methods: {
    onDragged({ el, deltaX, deltaY, offsetX, offsetY, clientX, clientY, first, last }) {
      if (first) {
        this.dragged = true
        return
      }
      if (last) {
        this.dragged = false
        return
      }
      var l = +window.getComputedStyle(el)['left'].slice(0, -2) || 0
      var t = +window.getComputedStyle(el)['top'].slice(0, -2) || 0
      el.style.left = l + deltaX + 'px'
      el.style.top = t + deltaY + 'px'
    }
  }
}
```

### Event Details

The argument passed to the callback function is an object containing the following properties:

#### el
- The target element on which the diretive binds.
- type: HTMLElement

#### first
- A boolean to indicate whether it is the first move of the drag. (drag starts here).
- type: Boolean

#### last
- A boolean to indicate whether it is the last move of the drag. (drag ends here).
- type: Boolean

#### deltaX
- The change of the pointer (mouse/touch)'s **x** coordination  from the last position. `undefined` when `first` or `last` is `true`.
- type: Number

#### deltaY
- The change of the pointer (mouse/touch)'s **y** coordination  from the last position. `undefined` when `first` or `last` is `true`.
- type: Number

#### offsetX
- The change of the pointer (mouse/touch)'s **x** coordination  from **the starting position**. `undefined` when `first` or `last` is `true`.
- type: Number

#### offsetY
- The change of the pointer (mouse/touch)'s **y** coordination from **the starting position**. `undefined` when `first` or `last` is `true`.
- type: Number

#### clientX
- Current x coordination of the pointer (mouse/touch).
- type: Number

#### clientY
- Current y coordination of the pointer (mouse/touch).
- type: Number

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