Rectangle drag to move, Four corners drag to change size

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.