drag rotate resize style body min height 600px box background color 00BCD4 position relative user select none transform translate 50 50 box wrapper position absolute transform origin top left user select none dot height 10px width 10px background color 1E88E5 position absolute border radius 100px border 1px solid white user select none dot hover background color 0D47A1 dot left top top 5px left 5px cursor nw resize dot left bottom bottom 5px left 5px cursor sw resize dot right top top 5px right 5px cursor ne resize dot right bottom bottom 5px right 5px cursor se resize dot top mid top 5px left calc 50 5px cursor n resize dot left mid left 5px top calc 50 5px cursor w resize dot right mid right 5px top calc 50 5px cursor e resize dot bottom mid bottom 5px left calc 50 5px cursor s resize dot rotate top 30px left calc 50 5px cursor url https findicons com files icons 1620 crystal_project 16 rotate_ccw png auto rotate link position absolute width 1px height 15px background color 1E88E5 top 20px left calc 50 0 5px z index 1 style div class box wrapper div class box div style width 100 height 100 background color red contentEditable true test div div class dot rotate div div class dot left top div div class dot left bottom div div class dot top mid div div class dot bottom mid div div class dot left mid div div class dot right mid div div class dot right bottom div div class dot right top div div class rotate link div div div script function addResizer elmt const box elmt children 0 const boxWrapper elmt const minWidth 40 const minHeight 40 let initX initY mousePressX mousePressY initW initH initRotate function repositionElement x y boxWrapper style left x px boxWrapper style top y px function resize w h box style width w px box style height h px function rotateBox deg boxWrapper style transform rotate deg deg function getCurrentRotation el let st window getComputedStyle el null let tm st getPropertyValue webkit transform st getPropertyValue moz transform st getPropertyValue ms transform st getPropertyValue o transform st getPropertyValue transform none if tm none let values tm split 1 split 0 split let angle Math round Math atan2 values 1 values 0 180 Math PI return angle 0 angle 360 angle return 0 drag support box addEventListener mousedown function event if event target className indexOf dot 1 return initX this parentElement offsetLeft initY this parentElement offsetTop mousePressX event clientX mousePressY event clientY function eventMoveHandler event repositionElement initX event clientX mousePressX initY event clientY mousePressY window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false false done drag support handle resize let rightMid elmt querySelector right mid let leftMid elmt querySelector left mid let topMid elmt querySelector top mid let bottomMid elmt querySelector bottom mid let leftTop elmt querySelector left top let rightTop elmt querySelector right top let rightBottom elmt querySelector right bottom let leftBottom elmt querySelector left bottom function resizeHandler event left false top false xResize false yResize false initX boxWrapper offsetLeft initY boxWrapper offsetTop mousePressX event clientX mousePressY event clientY initW box offsetWidth initH box offsetHeight initRotate getCurrentRotation boxWrapper let initRadians initRotate Math PI 180 let cosFraction Math cos initRadians let sinFraction Math sin initRadians function eventMoveHandler event let wDiff event clientX mousePressX let hDiff event clientY mousePressY let rotatedWDiff cosFraction wDiff sinFraction hDiff let rotatedHDiff cosFraction hDiff sinFraction wDiff let newW initW newH initH newX initX newY initY if xResize if left newW initW rotatedWDiff if newW minWidth newW minWidth rotatedWDiff initW minWidth else newW initW rotatedWDiff if newW minWidth newW minWidth rotatedWDiff minWidth initW newX 0 5 rotatedWDiff cosFraction newY 0 5 rotatedWDiff sinFraction if yResize if top newH initH rotatedHDiff if newH minHeight newH minHeight rotatedHDiff initH minHeight else newH initH rotatedHDiff if newH minHeight newH minHeight rotatedHDiff minHeight initH newX 0 5 rotatedHDiff sinFraction newY 0 5 rotatedHDiff cosFraction resize newW newH repositionElement newX newY window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false rightMid addEventListener mousedown e resizeHandler e false false true false leftMid addEventListener mousedown e resizeHandler e true false true false topMid addEventListener mousedown e resizeHandler e false true false true bottomMid addEventListener mousedown e resizeHandler e false false false true leftTop addEventListener mousedown e resizeHandler e true true true true rightTop addEventListener mousedown e resizeHandler e false true true true rightBottom addEventListener mousedown e resizeHandler e false false true true leftBottom addEventListener mousedown e resizeHandler e true false true true handle rotation let rotatedot elmt querySelector rotate rotatedot addEventListener mousedown function event initX this offsetLeft initY this offsetTop mousePressX event clientX mousePressY event clientY let arrow elmt querySelector box let arrowRects arrow getBoundingClientRect let arrowX arrowRects left arrowRects width 2 let arrowY arrowRects top arrowRects height 2 function eventMoveHandler event let angle Math atan2 event clientY arrowY event clientX arrowX Math PI 2 rotateBox angle 180 Math PI window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false false resize 200 100 repositionElement 100 600 Math random 0 5 100 600 Math random 0 5 let ref document getElementsByClassName box wrapper 0 first resize let bb ref cloneNode true document body appendChild bb addResizer bb second let cc ref cloneNode true document body appendChild cc addResizer cc third addResizer ref script
t querySelector left top let rightTop elmt querySelector right top let rightBottom elmt querySelector right bottom let leftBottom elmt querySelector left bottom function resizeHandler event left false top false xResize false yResize false initX boxWrapper offsetLeft initY boxWrapper offsetTop mousePressX event clientX mousePressY event clientY initW box offsetWidth initH box offsetHeight initRotate getCurrentRotation boxWrapper let initRadians initRotate Math PI 180 let cosFraction Math cos initRadians let sinFraction Math sin initRadians function eventMoveHandler event let wDiff event clientX mousePressX let hDiff event clientY mousePressY let rotatedWDiff cosFraction wDiff sinFraction hDiff let rotatedHDiff cosFraction hDiff sinFraction wDiff let newW initW newH initH newX initX newY initY if xResize if left newW initW rotatedWDiff if newW minWidth newW minWidth rotatedWDiff initW minWidth else newW initW rotatedWDiff if newW minWidth newW minWidth rotatedWDiff minWidth initW newX 0 5 rotatedWDiff cosFraction newY 0 5 rotatedWDiff sinFraction if yResize if top newH initH rotatedHDiff if newH minHeight newH minHeight rotatedHDiff initH minHeight else newH initH rotatedHDiff if newH minHeight newH minHeight rotatedHDiff minHeight initH newX 0 5 rotatedHDiff sinFraction newY 0 5 rotatedHDiff cosFraction resize newW newH repositionElement newX newY window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false rightMid addEventListener mousedown e resizeHandler e false false true false leftMid addEventListener mousedown e resizeHandler e true false true false topMid addEventListener mousedown e resizeHandler e false true false true bottomMid addEventListener mousedown e resizeHandler e false false false true leftTop addEventListener mousedown e resizeHandler e true true true true rightTop addEventListener mousedown e resizeHandler e false true true true rightBottom addEventListener mousedown e resizeHandler e false false true true leftBottom addEventListener mousedown e resizeHandler e true false true true handle rotation let rotatedot elmt querySelector rotate rotatedot addEventListener mousedown function event initX this offsetLeft initY this offsetTop mousePressX event clientX mousePressY event clientY let arrow elmt querySelector box let arrowRects arrow getBoundingClientRect let arrowX arrowRects left arrowRects width 2 let arrowY arrowRects top arrowRects height 2 function eventMoveHandler event let angle Math atan2 event clientY arrowY event clientX arrowX Math PI 2 rotateBox angle 180 Math PI window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false false resize 200 100 repositionElement 100 600 Math random 0 5 100 600 Math random 0 5 let ref document getElementsByClassName box wrapper 0 first resize let bb ref cloneNode true document body appendChild bb addResizer bb second let cc ref cloneNode true document body appendChild cc addResizer cc third addResizer ref script