Javascript implements the element drag function hosted by the browser
2020-03-30 03:33:05
OfStack
//Hosted by the browser
//Passes a reference to the corresponding element object to the function
function candrag(drager) {
drager.onmousedown = function (down) {
var offx = drager.offsetLeft
var offy = drager.offsetTop;
var offxl = down.clientX - offx;
var offyl = down.clientY - offy;
window.condition = 0;//Added the condition attribute to the window to resolve the conflict with click
document.onmousemove = function (move) {
drager.style.left = move.clientX - offxl + "px";
drager.style.top = move.clientY - offyl + "px";
drager.style.cursor = "move";
condition = Math.abs(move.clientX - down.clientX) + Math.abs(move.clientY - down.clientY);
}
}
drager.onmouseup = function () {
document.onmousemove = null;
draggerr.style.cursor = "auto";
}
}