mirror of
https://github.com/KevinMidboe/vue-js-modal.git
synced 2025-10-29 18:00:20 +00:00
Added minWidth and minHeigh, updated example
This commit is contained in:
@@ -10,7 +10,10 @@
|
|||||||
v-on:mousedown.stop
|
v-on:mousedown.stop
|
||||||
ref="modal">
|
ref="modal">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
<resizer v-if="resizable" @resize="resize"/>
|
<resizer v-if="resizable"
|
||||||
|
:min-width="minWidth"
|
||||||
|
:min-height="minHeight"
|
||||||
|
@resize="resize"/>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
</div>
|
</div>
|
||||||
@@ -118,8 +121,8 @@
|
|||||||
computed: {
|
computed: {
|
||||||
position() {
|
position() {
|
||||||
return {
|
return {
|
||||||
left: (this.window.width - this.modal.width) / 2,
|
left: Math.max((this.window.width - this.modal.width) / 2, 0),
|
||||||
top: (this.window.height - this.modal.height) / 2
|
top: Math.max((this.window.height - this.modal.height) / 2, 0)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
modalClass() {
|
modalClass() {
|
||||||
@@ -140,13 +143,17 @@
|
|||||||
this.window.height = window.innerHeight;
|
this.window.height = window.innerHeight;
|
||||||
|
|
||||||
if (this.adaptive) {
|
if (this.adaptive) {
|
||||||
this.modal.width = this.window.width > this.width
|
var width = this.window.width > this.width
|
||||||
? this.width
|
? this.width
|
||||||
: this.window.width
|
: this.window.width
|
||||||
|
|
||||||
this.modal.height = this.window.height > this.height
|
/*this.modal.height*/
|
||||||
|
var height = this.window.height > this.height
|
||||||
? this.height
|
? this.height
|
||||||
: this.window.height;
|
: this.window.height;
|
||||||
|
|
||||||
|
this.modal.width = width;//Math.max(width, this.minWidth);
|
||||||
|
this.modal.height = height;//Math.max(height, this.minHeight);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
genEventObject(params) {
|
genEventObject(params) {
|
||||||
@@ -224,7 +231,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nice-modal-fade-enter-active, .nice-modal-fade-leave-active {
|
.nice-modal-fade-enter-active, .nice-modal-fade-leave-active {
|
||||||
transition: all 0.5s;
|
transition: all 0.4s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nice-modal-fade-enter, .nice-modal-fade-leave-active {
|
.nice-modal-fade-enter, .nice-modal-fade-leave-active {
|
||||||
|
|||||||
@@ -5,13 +5,18 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'Resizer',
|
name: 'Resizer',
|
||||||
|
props: {
|
||||||
|
minHeight: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
minWidth: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
}},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
clicked: false,
|
clicked: false,
|
||||||
min: {
|
|
||||||
height: 50,
|
|
||||||
width: 0
|
|
||||||
},
|
|
||||||
size: {}
|
size: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -19,13 +24,11 @@ export default {
|
|||||||
this.$el.addEventListener('mousedown', this.start, false);
|
this.$el.addEventListener('mousedown', this.start, false);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
start(event) {
|
start() {
|
||||||
this.clicked = true;
|
this.clicked = true;
|
||||||
|
|
||||||
window.addEventListener('mousemove', this.mousemove, false);
|
window.addEventListener('mousemove', this.mousemove, false);
|
||||||
window.addEventListener('mouseup', this.stop, false);
|
window.addEventListener('mouseup', this.stop, false);
|
||||||
|
|
||||||
event.stopPropagation();
|
|
||||||
},
|
},
|
||||||
stop() {
|
stop() {
|
||||||
this.clicked = false;
|
this.clicked = false;
|
||||||
@@ -44,24 +47,19 @@ export default {
|
|||||||
resize(event) {
|
resize(event) {
|
||||||
var el = this.$el.parentElement;
|
var el = this.$el.parentElement;
|
||||||
|
|
||||||
if (event.clientX < window.innerWidth / 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (el) {
|
if (el) {
|
||||||
var width = event.clientX - el.offsetLeft;
|
var width = event.clientX - el.offsetLeft;
|
||||||
var height = event.clientY - el.offsetTop;
|
var height = event.clientY - el.offsetTop;
|
||||||
|
|
||||||
if (height < this.min.height) {
|
if (height < this.minHeight) {
|
||||||
height = this.min.height;
|
height = this.minHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width < this.min.width) {
|
if (width < this.minWidth) {
|
||||||
width = this.min.width;
|
width = this.minWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.size = {width, height};
|
this.size = {width, height};
|
||||||
|
|
||||||
el.style.width = width + 'px';
|
el.style.width = width + 'px';
|
||||||
el.style.height = height + 'px';
|
el.style.height = height + 'px';
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<h2>Vue.js Modal</h2>
|
<h2>Vue.js Modal</h2>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
npm install --save vue-js-modal
|
||||||
|
</pre>
|
||||||
<modal name="example-modal"
|
<modal name="example-modal"
|
||||||
transition="nice-modal-fade"
|
transition="nice-modal-fade"
|
||||||
:delay="200"
|
:min-width="200"
|
||||||
|
:min-height="200"
|
||||||
|
:delay="100"
|
||||||
:adaptive="adaptive"
|
:adaptive="adaptive"
|
||||||
:resizable="resizable">
|
:resizable="resizable">
|
||||||
<div style="height: 100%; box-sizing: border-box; padding: 10px; font-size: 13px; overflow: auto">
|
<div style="height: 100%; box-sizing: border-box; padding: 10px; font-size: 13px; overflow: auto">
|
||||||
@@ -87,9 +93,16 @@ export default {
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 50px;
|
padding: 50px;
|
||||||
|
cursor: default;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
color: #595959;
|
||||||
|
background-color: #f3f3f3;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
font-family: 'Avenir', Helvetica, Arial, sans-serif;
|
font-family: 'Avenir', Helvetica, Arial, sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
@@ -101,4 +114,23 @@ h1, h2 {
|
|||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
outline: none;
|
||||||
|
background: white;
|
||||||
|
border: 0;
|
||||||
|
padding: 6px 18px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
background: white;
|
||||||
|
|
||||||
|
color: #4db3ff;
|
||||||
|
border: 1px solid #4db3ff;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #20a0ff;
|
||||||
|
border: 1px solid #20a0ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user