This commit is contained in:
fan 2022-07-08 16:34:27 +08:00
commit 19f2b8c290

View File

@ -14,6 +14,8 @@ export default {
/** 鼠标按下,计算当前元素距离可视区的距离*/ /** 鼠标按下,计算当前元素距离可视区的距离*/
const disX = e.clientX - dialogHeaderEl.offsetLeft; const disX = e.clientX - dialogHeaderEl.offsetLeft;
const disY = e.clientY - dialogHeaderEl.offsetTop; const disY = e.clientY - dialogHeaderEl.offsetTop;
const oY = e.offsetY;
const bY = dialogHeaderEl.offsetHeight - e.offsetY;
/** 获取到的值带px 正则匹配替换*/ /** 获取到的值带px 正则匹配替换*/
let styL, styT; let styL, styT;
@ -32,9 +34,16 @@ export default {
document.onmousemove = function (e) { document.onmousemove = function (e) {
e.stopPropagation(); e.stopPropagation();
let cY = e.clientY;
if (cY < oY) {
cY = oY;
}
if (cY > document.body.clientHeight - bY) {
cY = document.body.clientHeight - bY;
}
/** 通过事件委托,计算移动的距离*/ /** 通过事件委托,计算移动的距离*/
const l = e.clientX - disX; const l = e.clientX - disX;
const t = e.clientY - disY; const t = cY - disY;
/** 移动当前元素*/ /** 移动当前元素*/
dragDom.style.left = `${l + styL}px`; dragDom.style.left = `${l + styL}px`;