Skip to content

Commit 53f7cd2

Browse files
Added props parentW & parentH
Added props: parentW & parentH see documentation and demo
1 parent d386194 commit 53f7cd2

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ If the prop is enabled, the component is oriented only to the specified.
113113
<vue-drag-resize :isActive="true">
114114
```
115115

116+
#### parentW
117+
Type: `Number`<br>
118+
Required: `false`<br>
119+
Default: `0`
120+
121+
Define the initial width of the parent element. If not specified it calculated automatically.
122+
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.
123+
124+
```html
125+
<vue-drag-resize :w="200">
126+
```
127+
128+
#### parentH
129+
Type: `Number`<br>
130+
Required: `false`<br>
131+
Default: `0`
132+
133+
Define the initial height of the parent element. If not specified it calculated automatically.
134+
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.
135+
136+
```html
137+
<vue-drag-resize :w="200">
138+
```
139+
116140
#### isDraggable
117141
Type: `Boolean`<br>
118142
Required: `false`<br>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-drag-resize",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Vue Component for resize and drag elements",
55
"author": "Kirill Murashov <me@kirillmurashov.com>",
66
"main": "dist/index.js",

src/components/vue-drag-resize.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ export default {
1919
parentLimitation: {
2020
type: Boolean, default: true
2121
},
22+
parentW: {
23+
type: Number,
24+
default: 0,
25+
validator: function (val) {
26+
return val >= 0
27+
}
28+
},
29+
parentH: {
30+
type: Number,
31+
default: 0,
32+
validator: function (val) {
33+
return val >= 0
34+
}
35+
},
2236
w: {
2337
type: Number,
2438
default: 100,
@@ -127,9 +141,9 @@ export default {
127141

128142
mounted: function () {
129143
this.parentElement = this.$el.parentNode;
144+
this.parentWidth = this.parentW ? this.parentW : this.parentElement.clientWidth;
145+
this.parentHeight = this.parentH ? this.parentH : this.parentElement.clientHeight;
130146

131-
this.parentWidth = this.parentElement.clientWidth;
132-
this.parentHeight = this.parentElement.clientHeight;
133147
this.rawRight = this.parentWidth - this.rawWidth - this.rawLeft;
134148
this.rawBottom = this.parentHeight - this.rawHeight - this.rawTop;
135149

@@ -692,6 +706,18 @@ export default {
692706

693707
let delta = this.height- this.h;
694708
this.rawBottom = this.bottom + delta;
709+
},
710+
711+
parentW(val){
712+
this.right = val - this.width - this.left;
713+
this.parentWidth = val;
714+
715+
},
716+
717+
parentH(val){
718+
this.bottom = val - this.height - this.top;
719+
this.parentHeight = val;
720+
695721
}
696722
}
697723
}

src/demo/app.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<template>
22
<div id="app">
3-
<div class="list">
3+
<div class="list" id="list">
44
<VueDragResize v-for="(rect, index) in rects"
55
:w="rect.width"
66
:h="rect.height"
77
:x="rect.left"
88
:y="rect.top"
9+
:parentW="listWidth"
10+
:parentH="listHeight"
911
:axis="rect.axis"
1012
:isActive="rect.active"
1113
:minw="rect.minw"
@@ -75,7 +77,22 @@
7577
toolbar
7678
},
7779
80+
data(){
81+
return {
82+
listWidth: 0,
83+
listHeight: 0
84+
}
85+
},
86+
7887
mounted() {
88+
let listEl = document.getElementById('list');
89+
this.listWidth = listEl.clientWidth;
90+
this.listHeight = listEl.clientHeight;
91+
92+
window.addEventListener('resize', ()=>{
93+
this.listWidth = listEl.clientWidth;
94+
this.listHeight = listEl.clientHeight;
95+
})
7996
},
8097
8198
computed: {

0 commit comments

Comments
 (0)