![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
draggable-vue-directive
Advanced tools
A simple directive to handle drag and drop of any Vue component
Vue directive (Vue.js 2.x) for handling element drag & drop.
npm install draggable-vue-directive --save
You can view the live demo here: https://israelzablianov.github.io/draggable-demo
<div v-draggable>
classic draggable
</div>
.vue
file:
import { Draggable } from 'draggable-vue-directive'
...
export default {
directives: {
Draggable,
},
...
<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
ValueThe 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
onPositionChange
onDragEnd
onDragStart
resetInitialPos
initialPosition
stopDragging
boundingRect
boundingElement
boundingRectMargin
Type: HtmlElement | Vue
Required: false
There are two ways to use the draggable
directive, as shown in the demo above.
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);
}
}
...
Type: Function
Required: false
Emits only when dragging ends. Has the same functionality as onPositionChange
.
Type: Function
Required: false
Emits only when dragging starts. Has the same functionality as onPositionChange
.
Type: Boolean
Required: false
default: undefined
Returns to the initial position of the element, before it is mounted.
Type: Position
Required: false
default: undefined
Sets the absolute starting position of this element.
Will be applied when resetInitialPos
is true
.
Type: Boolean
Required: false
default: undefined
Immediately stop dragging.
Type: ClientRect
Required: false
default: undefined
Constrains dragging to within the bounds of the rectangle.
Type: HtmlElement
Required: false
default: undefined
Constrains dragging to within the bounds of the element.
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.
FAQs
A simple directive to handle drag and drop of any Vue component
The npm package draggable-vue-directive receives a total of 8,312 weekly downloads. As such, draggable-vue-directive popularity was classified as popular.
We found that draggable-vue-directive demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.