Original is 30495103, I have made a modification here, infringement of the deletion.
Dry: Here the first thing to pay attention to the operation of the four corners of the box, the length of the width will change, while the absolute positioning of the top,left may change, I made a mistake before, resulting in the mobile process box size changed, the position has changed
<! DOCTYPE html>Mouse click var ondragdown = function (e,type) {e = e | | window.event; var location = {X:e.x | | e.clientx, Y:E.Y | | e.clienty} CLICKX = e.x | | E.clientx; clicky = E.y | | E.clienty; obj = this; Obj.operatetype = type; box = document.getElementById ("box"); return false; } var onboxdragdown = function (e,type) {e = e | | window.event; var location = {X:e.x | | e.clientx, Y:E.Y | | e.clienty} CLICKX = e.x | | E.clientx; clicky = E.y | | E.clienty; obj = this; Obj.operatetype = type; box = document.getElementById ("box"); return false; } var onupleftbtn = function (e) {e.stoppropagation (); Ondragdown (E, "NW"),} var onuprightbtn = function (e) {E.stoppropaga tion (); Ondragdown (E, "ne"); } var ondownleftbtn = function (e) {e.stoppropagation (); Ondragdown (E, "SW");} var ondownrightbtn = function (e) {E.stoppro Pagation (); Ondragdown (E, "se"); } var onboxdown = function (e) {Onboxdragdown (E, "move");}
var move = function (type,location,tarobj) {switch (type) {case ' n ': var add_length = clicky-location.y; clicky = Locati ON.Y; var length = parseint (tarobj.style.height) + add_length; Tarobj.style.height = length + "px"; Tarobj.style.top = clicky + "px"; Break Case ' s ': var add_length = CLICKY-LOCATION.Y; Clicky = LOCATION.Y; var length = parseint (tarobj.style.height)-add_length; Tarobj.style.height = length + "px"; Break Case ' W ': var add_length = clickx-location.x; Clickx = location.x; var length = parseint (tarobj.style.width) + add_length; Tarobj.style.width = length + "px"; Tarobj.style.left = Clickx + "px"; Break Case ' E ': var add_length = clickx-location.x; Clickx = location.x; var length = parseint (tarobj.style.width)-add_length; Tarobj.style.width = length + "px"; Break Case ' move ': var add_ylength = CLICKY-LOCATION.Y; Clicky = LOCATION.Y; var length = parseint (tarobj.style.top)-add_ylength; Tarobj.style.height = length + "px"; Tarobj.style.top = length +"PX"; var add_xlength = clickx-location.x; Clickx = location.x; var xlength = parseint (tarobj.style.left)-add_xlength; Tarobj.style.width = length + "px"; Tarobj.style.left = xlength + "px"; Break } }
Window.onload = function (e) {document.getElementById ("upleftbtn"). onmousedown = onupleftbtn; document.getElementById ("Uprightbtn"). onmousedown = onuprightbtn; document.getElementById ("Downleftbtn"). onmousedown = ondownleftbtn; document.getElementById ("Downrightbtn"). onmousedown = ondownrightbtn;
document.getElementById ("box"). onmousedown = Onboxdown;
Document.onmousemove = function (e) {if (obj) {e = e | | window.event; var location = {X:e.x | | e.clientx, Y:E.Y | | e.clien TY} switch (obj.operatetype) {case "NW": Move (' n ', location,box); Move (' W ', location,box); break; case "NE": Move (' n ', Loca Tion,box); Move (' e ', location,box); Break Case "SW": Move (' s ', location,box); Move (' W ', Location,box); Break Case "se": Move (' s ', location,box); Move (' e ', location,box); Break Case "Move": Move (' move ', location,box); Break }}} Document.onmouseup = function () {document.body.style.cursor = "auto"; obj = null;}}
</script>
Rectangle drag to move, Four corners drag to change size