This example describes the JavaScript implementation scalable display area effect code. Share to everyone for your reference, specific as follows:
This shows a scalable display area, the use of JS code to achieve, the mouse hold down the area of the lower right corner, drag and drop arrows, downward or upward pull, you can achieve scaling operations, when the area is smaller to show the scroll bar, usually also more common effect, this will be the JavaScript code to share.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-ksf-box-style-demo/
The specific code is as follows:
<HTML> <HEAD> <TITLE> Scalable display area </TITLE> <style type=text/css> body {margin-top:0px; font-size:9pt; margin-left:0px; margin-right:0px; font-family: "Song Body"} A {font-weight:400; font-size:9pt; Color:black; Text-decoration:none} a:hover {font-weight:400; font-size:9pt; color:red; Text-decoration:underline} a:active {font:9pt "song body"; Cursor:hand; COLOR: #ff0033}. STYLE1 {font-family: "Chinese Cloud", "XXFarEastFont-Imitation", "XXFarEastFont-Arial", "XXFarEastFont-Arial", "XXFarEastFont-Xingkai", "XXFarEastFont-Arial", "Neo-Arial", "Young Circle"}.
STYLE2 {font-family: "founder Yao Body";
Font-weight:bold; } </STYLE> <meta http-equiv=content-type content= "text/html; charset=gb2312 "> </HEAD> <body bgcolor= #fef4d9 > <CENTER> <span class=" STYLE1 "><font Color=black size=16> Scalable Display area </FONT></span> </CENTER><BR> <CENTER> <table bordercolor= #00FF00 border=5 borderlight= "green" > <TBODY> <TR> <td align=left> <style>unkn OWN {box-sizing:border-box; moz-box-siZing:border-box} #testDiv {border-right:white 2px outset; padding-right:2px; background-position:0% 50%; Border-top:white 2px outset; padding-left:2px; Z-index:2; Background-attachment:scroll; left:30px; padding-bottom:2px; margin:0px; Overflow:hidden; Border-left:white 2px outset; width:500px; COLOR: #3969a5; padding-top:2px; Border-bottom:white 2px outset; Background-repeat:repeat; height:300px; Background-color:buttonface} body {font-size:9pt; Font-family:verdana} #innerNice {border-right:white 2px inset; padding-right:8px; background-position:0% 50%; Border-top:white 2px inset; padding-left:8px; Background-attachment:scroll; padding-bottom:8px; Overflow:auto; Border-left:white 2px inset; width:100%; COLOR: #3969a5; padding-top:8px; Border-bottom:white 2px inset; Background-repeat:repeat; height:100%; Background-color:white} </STYLE> <div class=resizeme id=testdiv> <div id=innernice> <P Align=cen Ter> </P>
<p align=center> Please drag the mouse at the border </P> <P> </P> <P> </P> <P> </p></div>& Lt;/div> <script language=javascript> var theobject = null; This is gets a value as soon as a resize start 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;
The 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 (xMi N, 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-theobj
Ect.graby) + "px"; if (Dir.indexof ("W")!=-1) {theobject.el.style.left = Math.min (Theobject.left + window.event.clientx-theobject.grab
X, 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.gr
Aby, 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> </TD></TR></TBODY></TABLE> </CENTER> </BODY> </HTML>
I hope this article will help you with your JavaScript programming.