All Projects → IsraelZablianov → Draggable Vue Directive

IsraelZablianov / Draggable Vue Directive

Licence: mit
Vue2 directive that handles drag & drop

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Draggable Vue Directive

Vuebar
(🗃️ Archived) Vue 2 directive for custom scrollbar that uses native scroll behavior. Lightweight, performant, customizable and without dependencies. Used successfully in production on https://ggather.com
Stars: ✭ 650 (+127.27%)
Mutual labels:  directive, vuejs2, vue2, vue-directive
vue-drag-zone
Drag Zone component for @vuejs
Stars: ✭ 127 (-55.59%)
Mutual labels:  drag-and-drop, vue2, draggable, vue-directive
Vue Codemirror
⌨️ @codemirror component for @vuejs
Stars: ✭ 2,115 (+639.51%)
Mutual labels:  vuejs2, vue2, vue-directive
Vue Quill Editor
🍡@quilljs editor component for @vuejs
Stars: ✭ 6,874 (+2303.5%)
Mutual labels:  vuejs2, vue2, vue-directive
Vue Awesome Swiper
🏆 Swiper component for @vuejs
Stars: ✭ 12,072 (+4120.98%)
Mutual labels:  vuejs2, vue2, vue-directive
Vue Drag Drop
A lightweight Vue wrapper that abstracts away the wonkier parts of the Drag and Drop Browser API
Stars: ✭ 444 (+55.24%)
Mutual labels:  drag-and-drop, vuejs2, vue2
Dragmove.js
A super tiny Javascript library to make DOM elements draggable and movable. ~500 bytes and no dependencies.
Stars: ✭ 757 (+164.69%)
Mutual labels:  drag-and-drop, draggable, move
Vue Smooth Dnd
Vue wrapper components for smooth-dnd
Stars: ✭ 1,121 (+291.96%)
Mutual labels:  drag-and-drop, draggable, vuejs2
Easy Dnd
A drag and drop implementation for Vue.js 2 https://codesandbox.io/s/easy-dnd-demo-9mbij https://codesandbox.io/s/easy-dnd-demo-2-xnqbz
Stars: ✭ 202 (-29.37%)
Mutual labels:  drag-and-drop, vuejs2, vue2
dflex
The sophisticated Drag and Drop library you've been waiting for 🥳
Stars: ✭ 806 (+181.82%)
Mutual labels:  drag-and-drop, draggable
react-web-editor
The react-web-editor is a WYSIWYG editor library. you can resize and drag your component. It also has simple rich text editor
Stars: ✭ 191 (-33.22%)
Mutual labels:  drag-and-drop, draggable
vue2-loading
vue-loading presented in Vue2
Stars: ✭ 15 (-94.76%)
Mutual labels:  directive, vue2
vue-dnd-zone
vue.js plugin for drag and drop functionality
Stars: ✭ 144 (-49.65%)
Mutual labels:  drag-and-drop, draggable
el-table-draggable
让element-ui的table可拖动排序,支持 行,列,跨表格等特性
Stars: ✭ 68 (-76.22%)
Mutual labels:  drag-and-drop, draggable
v-drag-drop
Minimalistic drag & drop directives for Vue.js
Stars: ✭ 17 (-94.06%)
Mutual labels:  drag-and-drop, directive
v-drag
The simplest way to integrate dragging on Vue.js
Stars: ✭ 71 (-75.17%)
Mutual labels:  vue2, draggable
v-lazy-img
simplistic vue.js directive for image lazy loading
Stars: ✭ 25 (-91.26%)
Mutual labels:  vuejs2, vue-directive
DncVueSample
A Vue.js + iview static html admin template project.
Stars: ✭ 17 (-94.06%)
Mutual labels:  vuejs2, vue2
react-drag-list
A simple draggable list component。
Stars: ✭ 30 (-89.51%)
Mutual labels:  drag-and-drop, draggable
vite-vue3-lowcode
vue3.x + vite2.x + vant + element-plus H5移动端低代码平台 lowcode 可视化拖拽 可视化编辑器 visual editor 类似易企秀的H5制作、建站工具、可视化搭建工具
Stars: ✭ 1,309 (+357.69%)
Mutual labels:  drag-and-drop, draggable

draggable-vue-directive

GitHub open issues npm download npm download per month npm version Package Quality vue2 MIT License

Vue directive (Vue.js 2.x) for handling element drag & drop.

Installation

npm install draggable-vue-directive --save

Demo

demo gif

You can view the live demo here: https://israelzablianov.github.io/draggable-demo

Examples

Without Handler

<div v-draggable>
    classic draggable
</div>

.vue file:

  import { Draggable } from 'draggable-vue-directive'
  ...
  export default {
        directives: {
            Draggable,
        },
  ...

With Handler

<div v-draggable="draggableValue">
    <div :ref="handleId">
        <img src="../assets/move.svg" alt="move">
    </div>
    drag and drop using handler
</div>

.vue file:

  import { Draggable } from 'draggable-vue-directive'
  ...
  export default {
        directives: {
            Draggable,
        },
        data() {
            return {
                handleId: "handle-id",
                draggableValue: {
                    handle: undefined
                }
            };
        },
        mounted() {
            this.draggableValue.handle = this.$refs[this.handleId];
        }
  ...

draggable Value

The object passed to the directive is called the directive’s value.
For example, in v-draggable="draggableValue", draggableValue can be an object containing the folowing fields:

handle

Type: HtmlElement | Vue
Required: false

There are two ways to use the draggable directive, as shown in the demo above.

  1. The simple use. Just to put the directive on any Vue component or HTML element, and…boom! The element is draggable.
  2. Using a handler. If you choose to use a handler, the component itself will only be draggable using the handler.

onPositionChange

Type: Function
Required: false

Sometimes you need to know the element’s coordinates while it’s being dragged.
Passing a callback to draggableValue will achieve this goal; while dragging the element, the callback will be executed with 3 params:

  • positionDiff
  • absolutePosition (the current position; the first time the directive is added to the DOM or being initialized, the value will be undefined, unless the element has left and top values)
  • event (the event object)
  import { Draggable } from 'draggable-vue-directive'
  ...
  export default {
        directives: {
            Draggable,
        },
        data() {
            return {
                draggableValue: {
                    onPositionChange: this.onPosChanged
                }
            };
        },
        methods: {
            onPosChanged: function(positionDiff, absolutePosition, event) {
                console.log("left corner", absolutePosition.left);
                console.log("top corner", absolutePosition.top);
            }
        }
  ...

onDragEnd

Type: Function
Required: false

Emits only when dragging ends. Has the same functionality as onPositionChange.

onDragStart

Type: Function
Required: false

Emits only when dragging starts. Has the same functionality as onPositionChange.

resetInitialPos

Type: Boolean
Required: false
default: undefined

Returns to the initial position of the element, before it is mounted.

initialPosition

Type: Position
Required: false
default: undefined

Sets the absolute starting position of this element.
Will be applied when resetInitialPos is true.

stopDragging

Type: Boolean
Required: false
default: undefined

Immediately stop dragging.

boundingRect

Type: ClientRect
Required: false
default: undefined

Constrains dragging to within the bounds of the rectangle.

boundingElement

Type: HtmlElement
Required: false
default: undefined

Constrains dragging to within the bounds of the element.

boundingRectMargin

Type: MarginOptions
Required: false
default: undefined

When using boundingRect or boundingElement, you can pass an object with top, left, bottom, and right properties, to define a margin between the elements and the boundaries.

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].