阿甘正传 下载el-dialog模态框拖拽1.拖拽效果
1.1 拖拽前
1.2 拖拽后
import Vue from 'vue';
// v-dialogDrag: 弹窗拖拽属性(重点给模态框添加这个属性模态框就能拖拽了)
Vue.directive('dialogDrag', { //属性名称dialogDrag,前⾯加v- 使⽤
bind(el, binding, vnode, oldVnode) {
const dialogHeaderEl = el.querySelector('.el-dialog__header');
const dragDom = el.querySelector('.el-dialog');
//dialogHeaderEl.style.cursor = 'move';
dialogHeaderEl.style.cssText += ';cursor:move;'
dragDom.style.cssText += ';top:0px;'
// 获取原有属性 ie dom元素.currentStyle ⽕狐⾕歌 ComputedStyle(dom元素, null);
const sty = (function() {
if (window.document.currentStyle) {
return (dom, attr) => dom.currentStyle[attr];
} el{
return (dom, attr) => getComputedStyle(dom, fal)[attr];
}
})()
4级考试成绩查询
/
/ ⿏标按下,计算当前元素距离可视区的距离
const disX = e.clientX - dialogHeaderEl.offtLeft;
const disY = e.clientY - dialogHeaderEl.offtTop;
const screenWidth = document.body.clientWidth; // body当前宽度
const screenHeight = document.documentElement.clientHeight; // 可见区域⾼度(应为body⾼度,可某些环境下⽆法获取)
const dragDomWidth = dragDom.offtWidth; // 对话框宽度
const dragDomheight = dragDom.offtHeight; // 对话框⾼度
const minDragDomLeft = dragDom.offtLeft;
const maxDragDomLeft = screenWidth - dragDom.offtLeft - dragDomWidth;
const minDragDomTop = dragDom.offtTop;
const maxDragDomTop = screenHeight - dragDom.offtTop - dragDomheight;
// 获取到的值带px 正则匹配替换
let styL = sty(dragDom, 'left');
let styT = sty(dragDom, 'top');
// 注意在ie中第⼀次获取到的值为组件⾃带50% 移动之后赋值为px
if(styL.includes('%')) {
styL = +document.body.clientWidth * (+place(/\%/g, '') / 100);
styT = +document.body.clientHeight * (+place(/\%/g, '') / 100);
}el {
styL = +place(/\px/g, '');
styT = +place(/\px/g, '');
};
// 通过事件委托,计算移动的距离
// 通过事件委托,计算移动的距离
let left = e.clientX - disX;
let top = e.clientY - disY;
// 边界处理
if (-(left) > minDragDomLeft) {
left = -(minDragDomLeft);
} el if (left > maxDragDomLeft) {
left = maxDragDomLeft;
}
if (-(top) > minDragDomTop) {
top = -(minDragDomTop);
} el if (top > maxDragDomTop) {
top = maxDragDomTop;
must的用法}
// 移动当前元素
dragDom.style.cssText += `;left:${left + styL}px;top:${top + styT}px;`; };
fact
};
}
}pico太郎
})
3.拖拽组件的引⼊,只要引⼊了directives.js即可
3.1引⼊
aggressor
import '../common/js/directives.js'
3.2⽰例
4.使⽤。
给el-dialog添加属性v-dialogDrag即可
代码:
<el-dialog
title="外币维护"
v-dialogDrag
size='mini'
:clo-on-click-modal="fal"
:visible.sync="dialogVisible"
width="400px"
@clo="clo">
<div class="mini-font mb-5 balance">
<el-form :model="form">
<el-form-item label="外币⾦额" :label-width="formLabelWidth">
<!-- <el-input v-model="form.fmMoney" :value="form.fmMoney | formatMoney1" auto-complete="off" size='mini'></el-input> --> <el-input-number
size='small'
winter是什么意思
:precision="2"
:controls="fal"
v-model="form.fmMoney"
auto-complete="off">
</el-input-number>
</el-form-item>
<el-form-item label="汇率" :label-width="formLabelWidth">
<!-- <el-input v-model="form.percent" auto-complete="off" size='mini'></el-input> -->
<el-input-number
size='small'
:precision="4"
:controls="fal"
v-model="form.percent"
streamer
auto-complete="off">
</el-input-number>
</el-form-item>
<el-form-item label="本位币⾦额" :label-width="formLabelWidth">
苏州培训<!-- <el-input v-model="form.balance" auto-complete="off" size='mini'></el-input> -->
<el-input-number
size='small'
:precision="2"
:controls="fal"48个英语音标发音
v-model="form.balance"
auto-complete="off">
</el-input-number>
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button type="primary" size='mini' @click="sureBtn">确定</el-button>
<el-button type="primary" size='mini' @click="clo">取消</el-button>
</span>
</el-dialog>