| <Html> <Head> <Title> drag a window </title> <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"> <Style type = 'text/css '> <! -- Body {font-size: 12px ;} A: visited {text-decoration: none; color: slategray ;} A: hover {text-decoration: underline; color: slategray ;} A: link {text-decoration: none; color: slategray ;} --> </Style> <Script language = JScript> <! -- Var x0 = 0, y0 = 0, x1 = 0, y1 = 0; Var offx = 6, offy = 6; Var moveable = false; Var hover = 'Orange ', normal =' #336699 '; // color; Var index = 10000; // z-index; // Start dragging; Function startDrag (obj) { If (event. button = 1) { // Lock the title bar; Obj. setCapture (); // Define the object; Var win = obj. parentNode; Var sha = win. nextSibling; // Record the mouse and layer position; X0 = event. clientX; Y0 = event. clientY; X1 = parseInt (win. style. left ); Y1 = parseInt (win. style. top ); // Record the color; Normal = obj. style. backgroundColor; // Change the style; Obj. style. backgroundColor = hover; Win. style. borderColor = hover; Obj. nextSibling. style. color = hover; Sha. style. left = x1 + offx; Sha. style. top = y1 + offy; Moveable = true; } } // Drag; Function drag (obj) { If (moveable) { Var win = obj. parentNode; Var sha = win. nextSibling; Win. style. left = x1 + event. clientX-x0; Win. style. top = y1 + event. clientY-y0; Sha. style. left = parseInt (win. style. left) + offx; Sha. style. top = parseInt (win. style. top) + offy; } } // Stop dragging; Function stopDrag (obj) { If (moveable) { Var win = obj. parentNode; Var sha = win. nextSibling; Var msg = obj. nextSibling; Win. style. borderColor = normal; Obj. style. backgroundColor = normal; Msg. style. color = normal; Sha. style. left = obj. parentNode. style. left; Sha. style. top = obj. parentNode. style. top; Obj. releaseCapture (); Moveable = false; } } // Obtain the focus; Function getFocus (obj) { If (obj. style. zIndex! = Index) { Index = index + 2; Var idx = index; Obj. style. zIndex = idx; Obj. nextSibling. style. zIndex = idx-1; } } // Minimize; Function min (obj) { Var win = obj. parentNode. parentNode; Var sha = win. nextSibling; Var tit = obj. parentNode; Var msg = tit. nextSibling; Var flg = msg. style. display = "none "; If (flg) { Win. style. height = parseInt (msg. style. height) + parseInt (tit. style. height) + 2*2; Sha. style. height = win. style. height; Msg. style. display = "block "; Obj. innerHTML = "0 "; } Else { Win. style. height = parseInt (tit. style. height) + 2*2; Sha. style. height = win. style. height; Obj. innerHTML = "2 "; Msg. style. display = "none "; } } // Create an object; Function xWin (id, w, h, l, t, tit, msg) { Index = index + 2; This. id = id; This. width = w; This. height = h; This. left = l; This. top = t; This. zIndex = index; This. title = tit; This. message = msg; This. obj = null; This. bulid = bulid; This. bulid (); } // Initialization; Function bulid () { Var str = "" + "<Div id = xMsg" + this. id + "" + "Style = '" + "Z-index:" + this. zIndex + ";" + "Width:" + this. width + ";" + "Height:" + this. height + ";" + "Left:" + this. left + ";" + "Top:" + this. top + ";" + "Background-color:" + normal + ";" + "Color:" + normal + ";" + "Font-size: 8pt ;" + "Font-family: Tahoma ;" + "Position: absolute ;" + "Cursor: default ;" + "Border: 2px solid" + normal + ";" + "'" + "Onmousedown = 'getfocus (this) '>" + "<Div" + "Style = '" + "Background-color:" + normal + ";" + "Width:" + (this. width-2*2) + ";" + "Height: 20 ;" + "Color: white ;" + "'" + "Onmousedown = 'startdrag (this )'" + "Onmouseup = 'stopdrag (this )'" + "Onmousemove = 'drag (this )'" + "Ondblclick = 'min (this. childNodes [1]) '" + ">" + "<Span style = 'width:" + (this. width-2*12-4) + "; padding-left: 3px; '>" + this. title + "</span>" + "<Span style = 'width: 12; border-width: 0px; color: white; font-family: webdings; 'onclick = 'min (this) '> 0 </span>" + "<Span style = 'width: 12; border-width: 0px; color: white; font-family: webdings; 'onclick = 'showhide (\" "+ this. id + "\", null) '> r </span>" + "</Div>" + "<Div style = '" + "Width: 100% ;" + "Height:" + (this. height-20-4) + ";" + "Background-color: white ;" + "Line-height: 14px ;" + "Word-break: break-all ;" + "Padding: 3px ;" + "'>" + This. message + "</div>" + "</Div>" + "<Div id = xMsg" + this. id + "bg style = '" + "Width:" + this. width + ";" + "Height:" + this. height + ";" + "Top:" + this. top + ";" + "Left:" + this. left + ";" + "Z-index:" + (this. zIndex-1) + ";" + "Position: absolute ;" + "Background-color: black ;" + "Filter: alpha (opacity = 40 );" + "'> </Div> "; Document. body. insertAdjacentHTML ("beforeEnd", str ); } // Display the hidden window Function ShowHide (id, dis ){ Var bdisplay = (dis = null )? (Document. getElementById ("xMsg" + id). style. display = "")? "None": ""): dis Document. getElementById ("xMsg" + id). style. display = bdisplay; Document. getElementById ("xMsg" + id + "bg"). style. display = bdisplay; } // --> </Script> <Script language = 'jscript'> <! -- Function initialize () { Var a = new xWin ("1", 160,200,200,200, "Window 1", "xWin Demo "); Var B = new xWin ("2", 240,200,100,100, "window 2", "Welcome "); Var c = new xWin ("3", 200,160,250, 50, "window 3", "Copyright "); ShowHide ("1", "none"); // hide window 1 } Window. onload = initialize; // --> </Script> </Head> <Base target = "_ blank"> <Body onselectstart = 'Return false' oncontextmenu = 'Return false'> <A onclick = "ShowHide ('1', null); return false;" href = ""> Windows 1 </a> <A onclick = "ShowHide ('2', null); return false;" href = ""> Windows 2 </a> <A onclick = "ShowHide ('3', null); return false;" href = ""> Windows 3 </a> </Body> </Html> |