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 ) );
var y= event.pageY || (event.clientY (document.documentElement.scrollTop || document.body.scrollTop ) );
return [x, y]; }
/* * 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();
this.end = function(idName) { down = 0; document.getElementById(idName).releaseCapture(); } }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn