当前位置:网站首页>El dialog drag and drop, the boundary problem is completely corrected, and the bug of the online version is fixed
El dialog drag and drop, the boundary problem is completely corrected, and the bug of the online version is fixed
2022-06-26 15:39:00 【hikktn】
Preface
Welcome to my blog , Please give me some praise 、 Collection 、 Pay attention to the third company !
Welcome to my knowledge base ,Java Start from scratch · Language sparrow
Your attention is my driving force !
CSDN Blog entries focused on problem solving , YuQue focuses on collecting and summarizing knowledge , Including sharing cutting-edge technologies .
demand
Can drag and drop 、 The boundary problem .
Modify the point 
reason

Look at the picture , This offsetHeight The margin is the distance of the box , But we counted the box in , Over calculate the height , Cause the pop-up box to run out of the page .
Basis of compilation js, named drag.js
export default {
bind(el, binding, vnode) {
const dialogHeaderEl = el.querySelector('.el-dialog__header')
const dragDom = el.querySelector('.el-dialog')
dialogHeaderEl.style.cursor = 'move'
dragDom.style.cssText += ';top:0px;'
// Get the original properties ie dom Elements .currentStyle Fox, Google window.getComputedStyle(dom Elements , null);
const getStyle = (function() {
if (window.document.currentStyle) {
return (dom, attr) => dom.currentStyle[attr]
} else {
return (dom, attr) => getComputedStyle(dom, false)[attr]
}
})()
dialogHeaderEl.onmousedown = (e) => {
// The mouse click , Calculate the distance between the current element and the visible area
const disX = e.clientX - dialogHeaderEl.offsetLeft
const disY = e.clientY - dialogHeaderEl.offsetTop
const screenWidth = document.body.clientWidth
const screenHeight = document.body.clientHeight
const minDragDomLeft = dragDom.offsetLeft
const maxDragDomLeft = screenWidth - dragDom.offsetLeft
const minDragDomTop = dragDom.offsetTop
const maxDragDomTop = screenHeight - dragDom.offsetTop
// Get the value band px Regular match replacement
let styL = getStyle(dragDom, 'left')
let styT = getStyle(dragDom, 'top')
if (styL.includes('%')) {
styL = +document.body.clientWidth * (+styL.replace(/\%/g, '') / 100)
styT = +document.body.clientHeight * (+styT.replace(/\%/g, '') / 100)
} else {
styL = +styL.replace(/px/g, '')
styT = +styT.replace(/px/g, '')
}
document.onmousemove = function(e) {
// Through event delegation , Calculate the distance of movement
let left = e.clientX - disX
let top = e.clientY - disY
// Boundary treatment
if (-(left) > minDragDomLeft) {
left = -minDragDomLeft
} else if (left > maxDragDomLeft) {
left = maxDragDomLeft
}
if (-(top) > minDragDomTop) {
top = -minDragDomTop
} else if (top > maxDragDomTop) {
top = maxDragDomTop
}
// Move the current element
dragDom.style.cssText += `;left:${
left + styL}px;top:${
top + styT}px;`
}
document.onmouseup = function(e) {
document.onmousemove = null
document.onmouseup = null
}
}
}
}
Edit directive file for outer layer use , named el-drag-dialog.js
import drag from './drag'
const install = function(Vue) {
Vue.directive('el-drag-dialog', drag)
}
if (window.Vue) {
window['el-drag-dialog'] = drag
Vue.use(install); // eslint-disable-line
}
drag.install = install
export default drag
stay vue Used in components
<el-dialog v-el-drag-dialog></el-dialog>
import elDragDialog from '@/directive/el-drag-dialog'
directives: {
elDragDialog },
Reference link :https://blog.csdn.net/weixin_46074961/article/details/106905396
边栏推荐
- 【ceph】CephFS 内部实现(二):示例--未消化
- Particle filter PF -- Application in maneuvering target tracking (particle filter vs extended Kalman filter)
- [tcapulusdb knowledge base] Introduction to tcapulusdb general documents
- 在重新格式化时不要删除自定义换行符(Don‘t remove custom line breaks on reformat)
- selenium将元素保存为图片
- Is it safe to open an account for mobile stock registration? Is there any risk?
- Unity C # e-learning (IX) -- wwwfrom
- Comparative analysis of restcloud ETL and kettle
- Seurat to h5ad summary
- 还存在过有键盘的kindle?
猜你喜欢

A blog to thoroughly master the theory and practice of particle filter (PF) (matlab version)

在校生学习生涯总结(2022)

Keil4 opens the single-chip microcomputer project to a blank, and the problem of 100% program blocking of cpu4 is solved

刷题笔记(十九)--二叉树:二叉搜索树的修改与构造

【C语言练习——打印空心上三角及其变形】

Don't remove custom line breaks on reformat
![[applet practice series] Introduction to the registration life cycle of the applet framework page](/img/82/5a9219a7c2ee211180cc4b2d138204.png)
[applet practice series] Introduction to the registration life cycle of the applet framework page

【ceph】cephfs caps简介

AbortController的使用

Particle filter PF - 3D CV target tracking with uniform motion (particle filter vs extended Kalman filter)
随机推荐
AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy
Audio and video learning (I) -- PTZ control principle
粒子滤波 PF——在机动目标跟踪中的应用(粒子滤波VS扩展卡尔曼滤波)
在哪个平台买股票开户安全?求指导
Unity C # e-learning (10) -- unitywebrequest (1)
【TcaplusDB知识库】TcaplusDB单据受理-建表审批介绍
sqlite加载csv文件,并做数据分析
[CEPH] Lock Notes of cephfs
Shell script multi process concurrent writing method example (high level cultivation)
golang 临时对象池优化
评价——TOPSIS
效率超级加倍!pycharm十个小技巧就是这么神
Use of abortcontroller
【TcaplusDB知识库】TcaplusDB常规单据介绍
CNN优化trick
手机上怎么开户?在线开户安全么?
面试高频 | 你追我赶的Flink双流join
JS simple deepcopy (Introduction recursion)
SAP GUI 770 Download
[tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction