<Html> <Head> <Title> drag to change the layer size </title> <Meta content = "text/html; charset = gb2312" http-equiv = "Content-Type"> <Style> { Box-sizing: border-box; moz-box-sizing: border-box } # TestDiv {background-color: buttonface; background-repeat: repeat; Background-attachment: scroll; color: # rja5; height: 300px; Left: 30px; overflow: hidden; width: 500; z-index: 2; Border: 2px outset white; margin: 0px; padding: 2px; Background-position: 0% 50%} Body {font-family: Verdana; font-size: 9pt} # InnerNice {background-color: white; background-repeat: repeat; Background-attachment: Scroll; color: #3969A5; height: 100%; overflow: auto; Width: 100%; border: 2px inset white; padding: 8px; Background-position: 0% 50%} </Style> <SCRIPT language = javascript> Var theobject = null; Function resizeObject (){ This. el = null; // pointer to the object This. dir = ""; // type of current resize (n, s, e, w, ne, nw, se, sw) This. grabx = null; // Some useful values This. graby = null; This. width = null; This. height = null; This. left = null; This. top = null; } Function getDirection (el ){ Var xPos, yPos, offset, dir; Dir = ""; XPos = window. event. offsetX; YPos = window. event. offsetY; Offset = 8; // The distance from the edge in pixels If (yPos <offset) dir + = "n "; Else if (yPos> el. offsetHeight-offset) dir + = "s "; If (xPos <offset) dir + = "w "; Else if (xPos> el. offsetWidth-offset) dir + = "e "; Return dir; } Function doDown (){ Var el = getReal (event. srcElement, "className", "resizeMe "); If (el = null ){ Theobject = null; Return; } Dir = getDirection (el ); If (dir = "") return; Theobject = new resizeObject (); Theobject. el = el; Theobject. dir = dir; Theobject. grabx = window. event. clientX; Theobject. graby = window. event. clientY; Theobject. width = el. offsetWidth; Theobject. height = el. offsetHeight; Theobject. left = el. offsetLeft; Theobject. top = el. offsetTop; Window. event. returnValue = false; Window. event. cancelBubble = true; } Function doUp (){ If (theobject! = Null ){ Theobject = null; } } Function doMove (){ Var el, xPos, yPos, str, xMin, yMin; XMin = 8; // The smallest width possible YMin = 8; // height El = getReal (event. srcElement, "className", "resizeMe "); If (el. className = "resizeMe "){ Str = getDirection (el ); // Fix the cursor If (str = "") str = "default "; Else str + = "-resize "; El. style. cursor = str; } // Dragging starts here If (theobject! = Null ){ If (dir. indexOf ("e ")! =-1) Theobject. el. style. width = Math. max (xMin, theobject. width + window. event. clientX-theobject. grabx) + "px "; If (dir. indexOf ("s ")! =-1) Theobject. el. style. height = Math. max (yMin, theobject. height + window. event. clientY-theobject. graby) + "px "; If (dir. indexOf ("w ")! =-1 ){ Theobject. el. style. left = Math. min (theobject. left + window. event. clientX-theobject. grabx, theobject. left + theobject. width-xMin) + "px "; Theobject. el. style. width = Math. max (xMin, theobject. width-window. event. clientX + theobject. grabx) + "px "; } If (dir. indexOf ("n ")! =-1 ){ Theobject. el. style. top = Math. min (theobject. top + window. event. clientY-theobject. graby, theobject. top + theobject. height-yMin) + "px "; Theobject. el. style. height = Math. max (yMin, theobject. height-window. event. clientY + theobject. graby) + "px "; } Window. event. returnValue = false; Window. event. cancelBubble = true; } } Function getReal (el, type, value ){ Temp = el; While (temp! = Null) & (temp. tagName! = "BODY ")){ If (eval ("temp." + type) = value ){ El = temp; Return el; } Temp = temp. parentElement; } Return el; } Document. onmousedown = doDown; Document. onmouseup = doUp; Document. onmousemove = doMove; </SCRIPT> </Head> <Body> <Div class = "resizeMe" id = "testDiv"> <Div id = "innerNice"> <P align = "center"> </p> <P align = "center"> Please drag the mouse at the border </p> <P> </p> <P> </p> <P> </p> </Div> </Div> </Body> </Html> |