forked from euvl/vue-js-modal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResizer.vue
110 lines (99 loc) · 2.17 KB
/
Resizer.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<div :class="className"></div>
</template>
<script>
import { inRange } from './util'
export default {
name: 'VueJsModalResizer',
props: {
minHeight: {
type: Number,
default: 0
},
minWidth: {
type: Number,
default: 0
}
},
data () {
return {
clicked: false,
size: {}
}
},
mounted () {
this.$el.addEventListener('mousedown', this.start, false)
},
computed: {
className () {
return { 'vue-modal-resizer': true, clicked: this.clicked }
}
},
methods: {
start (event) {
this.clicked = true
window.addEventListener('mousemove', this.mousemove, false)
window.addEventListener('mouseup', this.stop, false)
event.stopPropagation()
event.preventDefault()
},
stop () {
this.clicked = false
window.removeEventListener('mousemove', this.mousemove, false)
window.removeEventListener('mouseup', this.stop, false)
this.$emit('resize-stop', {
element: this.$el.parentElement,
size: this.size
})
},
mousemove (event) {
this.resize(event)
},
resize (event) {
var el = this.$el.parentElement
if (el) {
var width = event.clientX - el.offsetLeft
var height = event.clientY - el.offsetTop
width = inRange(this.minWidth, window.innerWidth, width)
height = inRange(this.minHeight, window.innerHeight, height)
this.size = { width, height }
el.style.width = width + 'px'
el.style.height = height + 'px'
this.$emit('resize', {
element: el,
size: this.size
})
}
}
}
}
</script>
<style>
.vue-modal-resizer {
display: block;
overflow: hidden;
position: absolute;
width: 12px;
height: 12px;
right: 0;
bottom: 0;
z-index: 9999999;
background: transparent;
cursor: se-resize;
}
.vue-modal-resizer::after {
display: block;
position: absolute;
content: '';
background: transparent;
left: 0;
top: 0;
width: 0;
height: 0;
border-bottom: 10px solid #ddd;
border-left: 10px solid transparent;
}
.vue-modal-resizer.clicked::after {
border-bottom: 10px solid #369be9;
}
</style>