Multi-directional Drag to change element size

Source: Internet
Author: User

Drag and drop:
1 onmousedown Storage Distance disx/y
2 onmousemove Modify left Top
3 OnMouseUp Release Resources

1<! DOCTYPE html>234<meta charset= "UTF-8" >5<title></title>6<style>7 #box {8 width:100px;9 height:100px;Tenbackground-color:red; One Position:absolute; A left:200px; - top:200px; -         } the  -</style> -<script> -Window.onload=function(){ +             varObox=document.getelementbyid (' box '); -  +obox.onmousedown=function(e) { Ae=e| |event; at                 var -Pos=fn.call ( This), -disy=E.clienty, -disx=E.clientx, -Disl= This. Offsetleft, -dist= This. OffsetTop, inw=Obox.offsetwidth, -H=Obox.offsetheight; to  +  -Document.onmousemove=function(e) { thee=e| |event; *  $                     varx= e.clientx-Disx,Panax Notoginsengy= e.clienty-Disy; -  the  +  A                     if(Inarr (POS, ' top ')!=-1){ the                         if(h-y>=50){ +obox.style.height=h-y+ ' px '; -obox.style.top=dist+y+ ' px '; $                         } $  -                     } -                     if(Inarr (POS, ' bottom ')!=-1){ the                         if(Y + h>=50) { -OBox.style.height = y + H + ' px ';Wuyi                         } the                     } -                     if(Inarr (POS, ' left ')!=-1){ Wu                         if(w-x>=50){ -obox.style.width=w-x+ ' px '; Aboutobox.style.left=disl+x+ ' px '; $                         } -  -                     } -  A                     if(Inarr (POS, ' right ')!=-1){ +                         if(x+w>=50){ theobox.style.width=x+w+ ' px '; -                         } $  the                     } the                 } thedocument.onmouseup=function(){ thedocument.onmousemove=document.onouseup=NULL; -                 } in             } the  the  AboutObox.onmousemove=fn; the            functionfn (e) { thee=e| |event; the  +                 var -disx=E.clientx, thedisy=E.clienty,Bayiw= This. offsetwidth, theH= This. offsetheight, theDisl= This. Offsetleft, -dist= This. OffsetTop, -pos=[]; the                  This. style.cursor= '; the                 if(disx<disl+10){ thePos.push (' left '); the                      This. style.cursor = ' w-resize '; -                 } the                 if(disx>disl+w-10){ thePos.push (' right '); the                      This. style.cursor = ' w-resize ';94                 } the                 if(disy<dist+10){ thePos.push (' Top '); the                      This. style.cursor = ' n-resize ';98                 } About                 if(disy>dist+h-10){ -Pos.push (' Bottom ');101                      This. style.cursor = ' n-resize ';102                 }103 104                 if(pos.length==2){ the                     if(Inarr (POS, ' top ')!=-1&&inarr (POS, ' right ')!=-1) | | (Inarr (POS, ' left ')!=-1&&inarr (pos, ' bottom ')!=-1)){106                          This. style.cursor= ' Ne-resize ';107}Else{108                          This. style.cursor= ' Nw-resize ';109                     } the 111                 } the                 returnPos;113             } the  the             functionInarr (arr,s) { the 117                  for(vari=0;i<arr.length;i++){118                     if(arr[i]==s) {119                         returni; -                     }121                 }122                 return-1;123             }124         } the</script>126127<body> - 129<div id= "box" ></div> the</body>131

Multi-directional Drag to change element 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.