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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ If you are looking for the version 1 of the component, it is available on the [v
* Restrict size and movement to parent element
* Snap element to custom grid
* Restrict drag to vertical or horizontal axis
* Restrict sizes to vertical or horizontal axis
* Maintain aspect ratio
* Touch enabled
* Use your own classes
Expand Down Expand Up @@ -403,6 +404,17 @@ Define the axis on which the element is draggable. Available values are `x`, `y`
<vue-draggable-resizable axis="x">
```

#### resizeAxis
Type: `String`<br>
Required: `false`<br>
Default: `both`

Define the axis on which the element is resizeable. Available values are `x`, `y` or `both`.

```html
<vue-draggable-resizable resizesAxis="x">
```

#### grid
Type: `Array`<br>
Required: `false`<br>
Expand Down
13 changes: 10 additions & 3 deletions src/components/vue-draggable-resizable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ export default {
default: 'both',
validator: (val) => ['x', 'y', 'both'].includes(val)
},
resizeAxis: {
type: String,
default: 'both',
validator: (val) => ['x', 'y', 'both'].includes(val)
},
grid: {
type: Array,
default: () => [1, 1]
Expand Down Expand Up @@ -620,13 +625,14 @@ export default {
let top = this.top
let right = this.right
let bottom = this.bottom
const axis = this.resizeAxis

const mouseClickPosition = this.mouseClickPosition
const lockAspectRatio = this.lockAspectRatio
const aspectFactor = this.aspectFactor

const tmpDeltaX = mouseClickPosition.mouseX - (e.touches ? e.touches[0].pageX : e.pageX)
const tmpDeltaY = mouseClickPosition.mouseY - (e.touches ? e.touches[0].pageY : e.pageY)
const tmpDeltaX = axis && axis !== 'y' ? mouseClickPosition.mouseX - (e.touches ? e.touches[0].pageX : e.pageX) : 0
const tmpDeltaY = axis && axis !== 'x' ? mouseClickPosition.mouseY - (e.touches ? e.touches[0].pageY : e.pageY) : 0

if (!this.widthTouched && tmpDeltaX) {
this.widthTouched = true
Expand Down Expand Up @@ -762,7 +768,8 @@ export default {
computed: {
style () {
return {
transform: `translate(${this.left}px, ${this.top}px)`,
// The following line is turning a resize into a drag.
// transform: `translate(${this.left}px, ${this.top}px)`,
width: this.computedWidth,
height: this.computedHeight,
zIndex: this.zIndex,
Expand Down