注意: 该程序在IE调试的,其他浏览器可能有BUG,见谅! 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>Insert title here</title> <!-- -- CSS -- set window style --> <link rel="stylesheet" type="text/css" href="main.css" />
<!-- -- JavaScript -- set function --> <script language="JavaScript" src="mywindow.js"> </script> <script> alert("XP Window以IE测试,其他浏览器可能有BUG请见谅! 基本功能+四边四角顶部拖拉都已实现!") alert("进行操作前,记得先初始化窗口哦!");
/* * create xp window and initialize */ var myW = new MyWindow(); function initialize() { myW.setBackgroundDiv("mywindow"); myW.setLeftDiv("mywindow_left"); myW.setRightDiv("mywindow_right"); myW.setBottomDiv("mywindow_bottom"); myW.setTopDiv("mywindow_top"); myW.initialEvent(); }
/* * list button event function */ function hiddenWindow() { myW.hidden(); }
function showWindow() { myW.show(); }
function setAdjust(adj) { myW.setAdjust(adj); }
function showMaxSize() { myW.showMaxSize(); }
function getTop() { myW.getTop(); }
function getLeft() { myW.getLeft(); }
function getWidth() { myW.getWidth(); }
function getHeight() { myW.getHeight(); }
function removeWindow() { myW.removeWindow(); }
function addObject() { myW.addObject(); }
function deleteObject() { myW.deleteObject(); }
/* * drag operation event function */ function start(idName) { myW.start(idName); }
<!-- -- set every div of window -- because cover proble, so order of set div is bottom, right/left, central, last top --> <div id="mywindow"> <!-- set bottom div --> <div id="mywindow_bottom"> <div id="mywindow_botton_right_corner" onmousedown="start("mywindow_botton_right_corner");" onmousemove="move("mywindow_botton_right_corner");" onmouseup="end("mywindow_botton_right_corner");"> </div> </div>
<!-- set right div --> <div id="mywindow_right" onmousedown="start("mywindow_right");" onmousemove="move("mywindow_right");" onmouseup="end("mywindow_right");"> </div>
<!-- set left div --> <div id="mywindow_left" onmousedown="start("mywindow_left");" onmousemove="move("mywindow_left");" onmouseup="end("mywindow_left")";> </div>
<!-- set central div, it is added object --> <div id = "central"></div>
<!-- set border of drag window --> <div id="mywindow_top_drag" onmousedown="start("mywindow_top_drag");" onmousemove="move("mywindow_top_drag");" onmouseup="end("mywindow_top_drag");"></div> <div id="mywindow_bottom_drag" onmousedown="start("mywindow_bottom_drag");" onmousemove="move("mywindow_bottom_drag");" onmouseup="end("mywindow_bottom_drag");"></div> </div> </body> </html>
复制代码 代码如下: /** * set select button, use list as button */ /* set list button */ li { display: inline; white-space: nowrap; float: left; border: 0 solid white; border-right-width: 2px; border-bottom-width: 10px; } /* set <a> */ a { background-color: purple; color: white; text-decoration: none; padding: 4px 6px; }
/* set <a>: hover */ a:hover { background-color: #FF5500; }
/* * set every div position */ div { position: absolute; }
/** * set window */ #mywindow { background-image: url("image/window_bgImage.png"); /* assign appear position */ top: 100px; left: 200px; /* assign initialization size of window */ width: 500px; height: 400px; } /** * set bottom div of window */ #mywindow_bottom { background-image: url("image/window_bottom_middle_border.bmp"); background-repeat: repeat-x; top: 374px; left: 0px; width: 100%; height: 26px; } /* set drag div of bottom */ #mywindow_botton_right_corner { background-image: url("image/window_control_drag.bmp"); background-repeat: no-repeat; top: 8px; left: 486px; width: 12px; height: 12px; cursor: nw-resize; }
/** * set right div of window */ #mywindow_left { background-image: url("image/window_left_border.bmp"); background-repeat: repeat-y; top: 0px; left: 0px; width: 4px; height: 100%; cursor: e-resize; } /** * set central div */ #central { top: 10%; left: 10%; width: 80%; height: 80%; }
/** * set left div of window */ #mywindow_right { background-image: url("image/window_right_border.bmp"); background-repeat: repeat-y; top: 0px; left: 100%; width: 4px; height: 100%; cursor: e-resize; }
/** * set top div of window */ #mywindow_top { background-image: url("image/window_top_header.bmp"); background-repeat: repeat-x; top: 0px; left: 0px; width: 100%; height: 30px; } /* set left corner div of top */ #mywindow_top_left_corner { top: 0px; left: 0px; background-image: url("image/window_top_left_corner.gif"); background-repeat: no-repeat; width: 8px; height: 100%; } /* set middle div of top, and set buttom image */ #mywindow_top_middle { top: 0px; left: 425px; } img.button { float: right; margin: 5px 1px; } /* set right corner div of top */ #mywindow_top_right_corner { top: 0px; left: 498px; background-image: url("image/window_top_right_corner.bmp"); background-repeat: no-repeat; width: 8px; height: 100%; }
复制代码 代码如下: function MyWindow() { /* background left right bottom top div */ var bgDiv = null; var leftDiv = null; var rightDiv = null; var bottomDiv = null; var topDiv = null;
/* old values of window */ var oldTop = 100; var oldLeft = 200; var oldWidth = 500; var oldHeight = 400; var clickTopDivX = null; var clickTopDivY = null;
/* record whether max size */ var maxSize = false; /* record whether adjust */ var adjust = true; /* record click whether in window */ var clickInWindow = false; /* record add object */ var addObj = null; /* record whether mouse is down*/ var down = 0;
/* * set five div of window */ this.setBackgroundDiv = function(idName) { bgDiv = document.getElementById(idName); }; this.setLeftDiv = function(idName) { leftDiv = document.getElementById(idName); };
/* * chang window size function * curTop curLeft: new top left corner coordinate * curRight curBottom: new bottom right corner coordinate * curWidth curHeight: new width and height * Boolean: whether record new data */ function changeWindowSize(curTop, curLeft, curWidth, curHeight, Boolean) { bgDiv.style.top = curTop; bgDiv.style.left = curLeft; bgDiv.style.width = curWidth; bgDiv.style.height = curHeight;
/* record new data */ if (Boolean) { oldTop = curTop; oldLeft = curLeft; oldWidth = curWidth; oldHeight = curHeight; } bottomDiv.style.top = curHeight - 26; var bDivRCorner = document.getElementById("mywindow_botton_right_corner"); bDivRCorner.style.left = curWidth - 12;
var tDivMiddleButtom = document.getElementById("mywindow_top_middle"); tDivMiddleButtom.style.left = curWidth - 72;
var tDivRightCorner = document.getElementById("mywindow_top_right_corner"); tDivRightCorner.style.left = curWidth - 2; }
/* change image of assign idName */ function changeImage(idName, imgSrc) { var image = document.getElementById(idName); image.src = imgSrc; }
/* show max size of window */ this.showMaxSize = function() { if (adjust) { maxSize = true;
/* * get top, left, width, height values of window */ this.getTop = function() { alert("My top pixel of window is: " + bgDiv.offsetTop); }
this.getLeft = function() { alert("My Left pixel of window is: " + bgDiv.offsetLeft); }
this.getWidth = function() { alert("My width pixel of window is: " + bgDiv.offsetWidth); }
this.getHeight = function() { alert("My height pixel of window is: " + bgDiv.offsetHeight); } /* * get mouse location * return [x, y]: x and y coordinate of mouse */ function getMouseXY() { var x = event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft ) );
/* * judge mouse click whether in window * in other words, judge window whether is lived */ function judgeClick() { /* get mouse click site */ var coor = getMouseXY();
/* judge whether in window */ var myW = document.getElementById("mywindow"); var closeImage = document.getElementById("top_close_button"); var maxImage = document.getElementById("top_max_button"); var minImage = document.getElementById("top_min_button");
/* * top button events function * there are mouse down, mouse move, mouse up and mouse move */ function closeMouseDown() { changeImage("top_close_button", "image/window_control_close_mousedown.bmp"); }
/* * drag events function */ this.start = function(idName) { if(idName == "mywindow_top") { var coor = getMouseXY(); clickTopDivX = coor[0]; clickTopDivY = coor[1]; } document.getElementById(idName).setCapture(); down = 1; }
this.move = function(idName) { var curTop = oldTop; var curLeft = oldLeft; var curWidth = oldWidth; var curHeight = oldHeight; var coor = getMouseXY();