/**窗口拖拽方法
* @param {HTMLElement} oDrag div元素
* @param {HTMLElement} handle 标题内容
*/
drag(oDrag, handle) {
if (!(oDrag instanceof HTMLElement)) {
return
}
if (handle && !(handle instanceof HTMLElement)) {
return
}
let dragDiv = null,
disX = 0,
disY = 0;
dragDiv = oDrag;
handle = handle || oDrag;
handle.style.cursor = "move";
handle.onmousedown = function (event) {
var event = event || window.event;
disX = event.clientX - oDrag.offsetLeft;
disY = event.clientY - oDrag.offsetTop;
document.onmousemove = function (ev) {
var iL = ev.clientX - disX;
var iT = ev.clientY - disY;
var maxL = document.documentElement.clientWidth - oDrag.offsetWidth;
var maxT = document.documentElement.clientHeight - oDrag.offsetHeight;
iL <= 0 && (iL = 0);
iT <= 0 && (iT = 0);
iL >= maxL && (iL = maxL);
iT >= maxT && (iT = maxT);
oDrag.style.left = iL + "px";
oDrag.style.top = iT + "px";
oDrag.style.bottom = "unset";
// oDrag.style.zIndex = '101';
return false;
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
};
return false;
};
}