Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div id="app">
<div style="height: 500px; width: 500px; margin: 20px; border: 1px solid red; position: relative;">
<vue-draggable-resizable :x="50" :y="50" :w="400" :h="400" :parent="true" @resizing="onResize" @dragging="onDrag">
<vue-draggable-resizable :x.sync="x" :y.sync="y" :w.sync="w" :h.sync="h" :parent="true" @resizing="onResize" @dragging="onDrag">
<p>Component</p>
</vue-draggable-resizable>
</div>
Expand All @@ -13,6 +13,9 @@ import VueDraggableResizable from './components/vue-draggable-resizable'

export default {
name: 'app',
data () {
return {x: 50, y: 50, w: 400, h: 400}
},
components: {
'vue-draggable-resizable': VueDraggableResizable
}
Expand Down
12 changes: 12 additions & 0 deletions src/components/vue-draggable-resizable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default {
}

this.$emit('resizing', this.left, this.top, this.width, this.height)
this.emitUpdates()
},
beforeDestroy: function () {
document.documentElement.removeEventListener('mousemove', this.handleMove, true)
Expand Down Expand Up @@ -253,6 +254,7 @@ export default {
}

this.$emit('resizing', this.left, this.top, this.width, this.height)
this.emitUpdates()
}

window.requestAnimationFrame(animate)
Expand Down Expand Up @@ -306,6 +308,7 @@ export default {
this.height = (Math.round(this.elmH / this.grid[1]) * this.grid[1])

this.$emit('resizing', this.left, this.top, this.width, this.height)
this.emitUpdates()
} else if (this.dragging) {
if (this.elmX + dX < this.parentX) this.mouseOffX = (dX - (diffX = this.parentX - this.elmX))
else if (this.elmX + this.elmW + dX > this.parentW) this.mouseOffX = (dX - (diffX = this.parentW - this.elmX - this.elmW))
Expand All @@ -324,22 +327,31 @@ export default {
}

this.$emit('dragging', this.left, this.top)
this.emitUpdates()
}
},
handleUp: function (e) {
this.handle = null
if (this.resizing) {
this.resizing = false
this.$emit('resizestop', this.left, this.top, this.width, this.height)
this.emitUpdates()
}
if (this.dragging) {
this.dragging = false
this.$emit('dragstop', this.left, this.top)
this.emitUpdates()
}
this.opacity = 1

this.elmX = this.left
this.elmY = this.top
},
emitUpdates: function () {
this.$emit('update:x', this.left)
this.$emit('update:y', this.top)
this.$emit('update:w', this.width)
this.$emit('update:h', this.height)
}
},
computed: {
Expand Down