All Projects → nil → v-drag

nil / v-drag

Licence: MIT license
The simplest way to integrate dragging on Vue.js

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to v-drag

vue2-data-tree
A tree that data is lazy loaded. Support dragging node, checking node, editing node's name and selecting node.
Stars: ✭ 41 (-42.25%)
Mutual labels:  drag, vue2, draggable
vue-input-autowidth
A Vue.js directive that automatically resizes an input's width to fit its contents.
Stars: ✭ 94 (+32.39%)
Mutual labels:  vue2, vue3
vue-ray
Debug your Vue 2 & 3 code with Ray to fix problems faster
Stars: ✭ 48 (-32.39%)
Mutual labels:  vue2, vue3
vue3-chat
2021👨‍🎓Vue2/3全家桶 + Koa+Socket+Vant3前后端分离移动端聊天应用。vue+node全栈入门项目
Stars: ✭ 46 (-35.21%)
Mutual labels:  vue2, vue3
React Rnd
🖱 A resizable and draggable component for React.
Stars: ✭ 2,560 (+3505.63%)
Mutual labels:  drag, draggable
react-native-dnd-board
A drag and drop Kanban board for React Native.
Stars: ✭ 41 (-42.25%)
Mutual labels:  drag, draggable
vue-drag-zone
Drag Zone component for @vuejs
Stars: ✭ 127 (+78.87%)
Mutual labels:  vue2, draggable
React Dragline
🐼Guide lines and magnetic adsorption to better align draggable elements in React.
Stars: ✭ 134 (+88.73%)
Mutual labels:  drag, draggable
draggable-polyfill
🌈a beautify polyfill for native drag!
Stars: ✭ 49 (-30.99%)
Mutual labels:  drag, draggable
drag-to-close
Android library that provides a view group which allows to finish an activity by dragging a view.
Stars: ✭ 69 (-2.82%)
Mutual labels:  drag, draggable
Vue3 Draggable Resizable
[Vue3 组件] 用于拖拽调整位置和大小的的组件,同时支持冲突检测,元素吸附对齐,实时参考线。
Stars: ✭ 159 (+123.94%)
Mutual labels:  drag, draggable
toggle
Vue 3 toggle component with labels, custom slots and styling options (+Tailwind CSS support).
Stars: ✭ 75 (+5.63%)
Mutual labels:  vue2, vue3
Ngx Smooth Dnd
angular wrapper for smooth-dnd
Stars: ✭ 152 (+114.08%)
Mutual labels:  drag, draggable
revue-draggable
A Vue component that makes anything draggable 🤏 Easy to use and control. Supports Vue3 and Vue2 🦾
Stars: ✭ 117 (+64.79%)
Mutual labels:  draggable, vue3
Luy Dragger
dragger with a render props
Stars: ✭ 135 (+90.14%)
Mutual labels:  drag, draggable
vue-insta-stories
Vue 2 & 3 library for Instagram like stories.
Stars: ✭ 45 (-36.62%)
Mutual labels:  vue2, vue3
Vue Smooth Dnd
Vue wrapper components for smooth-dnd
Stars: ✭ 1,121 (+1478.87%)
Mutual labels:  drag, draggable
React Smooth Dnd
react wrapper components for smooth-dnd
Stars: ✭ 1,560 (+2097.18%)
Mutual labels:  drag, draggable
vue-drr
A Vue2 component for draggable, resizable, rotatable elements
Stars: ✭ 34 (-52.11%)
Mutual labels:  vue2, draggable
vue3-smooth-dnd
Vue3 wrapper components for smooth-dnd
Stars: ✭ 92 (+29.58%)
Mutual labels:  draggable, vue3

v-drag

The simplest way to integrate drag on Vue.js.

Draggable elements are a common UX pattern, specially on touch screens. But as a developer, you might know how challenging it is to apply it with JavaScript. So to simplify things, v-drag was written. Its aim is to quickly integrate and customize draggable elements on projects using Vue.js.

Build status npm package Version License

Table of contents

  1. Installation
  2. Usage
  3. Options
    1. Axis
    2. Snap
    3. Handle
  4. Vue events
  5. Global configuration
    1. Event classes
    2. Remove transitions

Installation

npm install v-drag --save

v-drag’s source code is also available uncompressed and minified.

Usage

Import v-drag into any file you are planning to use it:

import drag from "v-drag"
const drag = require("v-drag");

Then call the v-drag plugin:

Vue.use(drag, {
  // global configuration
});

No extra setup is necessary at this point. Add the v-drag attribute to any element to make it draggable:

<div v-drag>Drag me!</div>

Options

The default behavior for any element with the v-drag attribute is to be draggable in any direction and without a handle. However, this can be changed using an object or its equivalent shortcuts:

<div v-drag="{ axis: 'x', handle: '#someElement' }">
  <div id="someElement">Handle</div>
</div>

Both the object and the values can be declared inline, as in the example above, or using the data object, computed properties, methods, props,…

Axis

Constrains the element to move only in one direction: horizontal or vertical.

Values

  • all: all directions default
  • x: horizontal movement
  • y: vertical movement

Shortcut

<div v-drag:x>Horizontal</div>

Snap

When dragging, the element will snap to the specified grid. You can use either a number or a string with units.

<div v-drag="{snap: 100}">Drag me in 100px increments</div>

Using an array, different values can be declared for each axis:

<div vdrag="{snap: [10, 50]}">
  Horizontal: 10px
  Vertical: 50px
</div>

Handle

Informs that the element can only be dragged using another element, known as handle. It’s not necessary for the handle to be located inside the draggable element, and each element can have more than one handle.

Values

Handle’s name must be a selector (the same used to refer to the element in CSS) or a Ref.

Shortcut

<div v-drag="'.someElement'">Don’t drag me</div>
<div class="someElement">Drag me</div>

Ref

To define handles using Refs, you must first set its value in data and replace it after the component is mounted:

<template>
  <div v-drag="{handle}">
    Drag me using handle
    <div ref="drag-handle">Handle</div>
  </div>
</template>

<script>

export default {
  data() {
    return {
      handle: undefined,
    }
  },

  mounted() {
    this.$data.handle = this.$refs.dragHandle
  }
};

</script>

Vue events

These events are emitted when the user makes the corresponding action.

<div v-drag @v-drag-end="someFunction()">
  Event on end
</div>
Event Description
@v-drag-setup The component has completed the initial setup
@v-drag-start The user has pressed the draggable element and its mouse or finger is down
@v-drag-moving The user is moving the mouse or finger
@v-drag-end The user has released its mouse or finger
@v-drag-update Changes in the configuration of the draggable options
@v-drag-axis-update The axis has been updated
@v-drag-handle-update The handle has been updated

Global configuration

Event classes

v-drag uses CSS classes to add basic styling to the draggable elements. You can override one or multiple of the default classes when the plugin is called:

Vue.use(drag, {
  eventClass: {
    down: "is-pressed",
    move: "is-moving"
  }
});

This are the default classes with its values:

Name Default value Description
initial drag-draggable The element is draggable
hasHandle drag-uses-handle The element uses a handle
handle drag-handle The element is the handle of another element
down drag-down The user has pressed the element
move drag-move The user has started to drag the element

Remove transitions

By default, v-drag removes all transition animations to keep the dragging as smooth as possible. However, if you want to enable them, you can:

Vue.use(drag, {
  removeTransition: false // default: `true`
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].