栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

html+css+js实现xp window界面及有关功能

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

html+css+js实现xp window界面及有关功能

注意: 该程序在IE调试的,其他浏览器可能有BUG,见谅!
复制代码 代码如下:




Insert title here










  • 初始化窗口

  • 隐藏窗口

  • 显示窗口

  • 设置窗口可调整大小

  • 设置窗口不可调整大小

  • 最大化窗口

  • 在窗口中添加对象

  • 删除对象

  • 得到Top的值

  • 得到Left的值

  • 得到Width的值

  • 得到Height的值

  • 释放窗口资源








onmousemove="move('mywindow_botton_right_corner');"
onmouseup="end('mywindow_botton_right_corner');">




onmouseup="end('mywindow_right');">



onmouseup="end('mywindow_left')";>






onmouseup="end('mywindow_top');">



/>
/>
/>






onmouseup="end('mywindow_right_corner');">

onmouseup="end('mywindow_left_corner');">

onmouseup="end('mywindow_rBottom_corner');">



onmouseup="end('mywindow_top_drag');">
onmouseup="end('mywindow_bottom_drag');">




复制代码 代码如下:


li {
display: inline;
white-space: nowrap;
float: left;
border: 0 solid white;
border-right-width: 2px;
border-bottom-width: 10px;
}

a {
background-color: purple;
color: white;
text-decoration: none;
padding: 4px 6px;
}


a:hover {
background-color: #FF5500;
}


div {
position: absolute;
}


#mywindow {
background-image: url("image/window_bgImage.png");

top: 100px;
left: 200px;

width: 500px;
height: 400px;
}

#mywindow_bottom {
background-image: url("image/window_bottom_middle_border.bmp");
background-repeat: repeat-x;
top: 374px;
left: 0px;
width: 100%;
height: 26px;
}

#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;
}


#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;
}

#central {
top: 10%;
left: 10%;
width: 80%;
height: 80%;
}


#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;
}


#mywindow_top {
background-image: url("image/window_top_header.bmp");
background-repeat: repeat-x;
top: 0px;
left: 0px;
width: 100%;
height: 30px;
}

#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%;
}

#mywindow_top_middle {
top: 0px;
left: 425px;
}
img.button {
float: right;
margin: 5px 1px;
}

#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%;
}

#mywindow_right_corner {
top: 0%;
left: 100%;
width: 4px;
height: 4px;
cursor: ne-resize;
}
#mywindow_left_corner {
top: 0%;
left: 0%;
width: 4px;
height: 4px;
cursor: nw-resize;
}
#mywindow_rBottom_corner {
top: 99%;
left: 0%;
width: 4px;
height: 4px;
cursor: ne-resize;
}
#mywindow_top_drag {
top: 0%;
left: 2%;
width: 96%;
height: 4px;
cursor: n-resize;
}
#mywindow_bottom_drag {
top: 99%;
left: 2%;
width: 96%;
height: 4px;
cursor: n-resize;
}


复制代码 代码如下:
function MyWindow() {

var bgDiv = null;
var leftDiv = null;
var rightDiv = null;
var bottomDiv = null;
var topDiv = null;


var oldTop = 100;
var oldLeft = 200;
var oldWidth = 500;
var oldHeight = 400;
var clickTopDivX = null;
var clickTopDivY = null;


var maxSize = false;

var adjust = true;

var clickInWindow = false;

var addObj = null;

var down = 0;


this.setBackgroundDiv = function(idName) {
bgDiv = document.getElementById(idName);
};
this.setLeftDiv = function(idName) {
leftDiv = document.getElementById(idName);
};

this.setRightDiv = function(idName) {
rightDiv = document.getElementById(idName);
};

this.setBottomDiv = function(idName) {
bottomDiv = document.getElementById(idName);
}

this.setTopDiv = function(idName) {
topDiv = document.getElementById(idName);
}


this.setAdjust = function(Boolean) {
adjust = Boolean;
}


this.initialEvent = function() {
document.onclick = judgeClick;

var close = document.getElementById("top_close_button");
close.onmouseover = closeMouseOver;
close.onmouseout = closeMouseOut;
close.onmousedown = closeMouseDown;
close.onclick = this.removeWindow;


var max = document.getElementById("top_max_button");
max.onmouseover = maxMouseOver;
max.onmouseout = maxMouseOut;
max.onmousedown = maxMouseDown;
max.onclick = showNormalOrMax;

var min = document.getElementById("top_min_button");
min.onmouseover = minMouseOver;
min.onmouseout = minMouseOut;
min.onmousedown = minMouseDown;
min.onclick = hiddenWindow;
}


this.hidden = function() {
bgDiv.style.display="none";
};


this.show = function() {
bgDiv.style.display="";
};


this.addObject = function(){
if (addObj == null) {
addObj = document.createElement("p");
addObj.innerHTML = "公鸡中的战斗机,OYE! 你太有才了!";
document.getElementById("central").appendChild(addObj);
}
}

this.deleteObject = function() {
addObj.parentNode.removeChild(addObj);
addObj = null;
}


function changeWindowSize(curTop, curLeft, curWidth, curHeight, Boolean) {
bgDiv.style.top = curTop;
bgDiv.style.left = curLeft;
bgDiv.style.width = curWidth;
bgDiv.style.height = curHeight;


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;
}


function changeImage(idName, imgSrc) {
var image = document.getElementById(idName);
image.src = imgSrc;
}


this.showMaxSize = function() {
if (adjust) {
maxSize = true;

changeImage("top_max_button", "image/window_control_resile_normall.bmp");

var maxWidth = screen.availWidth;
var maxHeight = screen.availHeight;
changeWindowSize(0, 0, maxWidth, maxHeight, false);
}
}


this.removeWindow = function() {
if (bgDiv != null)
bgDiv.parentNode.removeChild(bgDiv);
}


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);
}

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];
}


function judgeClick() {

var coor = getMouseXY();


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");

if (coor[0] >= myW.offsetLeft && coor[0] <= (myW.offsetLeft + myW.offsetWidth)
&& coor[1] >= myW.offsetTop && coor[1] <= (myW.offsetHeight + myW.offsetTop)) {
clickInWindow = true;

closeImage.src = "image/window_control_close_normall.bmp";

if(maxSize == true) {
maxImage.src = "image/window_control_resile_normall.bmp";
} else {
maxImage.src = "image/window_control_max_normall.bmp";
}

minImage.src = "image/window_control_min_normall.bmp";

} else {
clickInWindow = false;

closeImage.src = "image/window_control_close_blur.bmp";

if(maxSize == true) {
maxImage.src = "image/window_control_resile_blur.bmp";
} else {
maxImage.src = "image/window_control_max_blur.bmp";
}

minImage.src = "image/window_control_min_blur.bmp";
}
}


function closeMouseDown() {
changeImage("top_close_button", "image/window_control_close_mousedown.bmp");
}

function closeMouseOver() {
if(clickInWindow == true) {
changeImage("top_close_button", "image/window_control_close_mouseon.bmp");
} else {
changeImage("top_close_button", "image/window_control_close_blur.bmp");
}
}

function closeMouseOut() {
if(clickInWindow == true) {
changeImage("top_close_button", "image/window_control_close_normall.bmp");
} else {
changeImage("top_close_button", "image/window_control_close_blur.bmp");
}
}

function maxMouseDown(){
if (maxSize == true) {
changeImage("top_max_button", "image/window_control_resile_mousedown.bmp");
}
else {
changeImage("top_max_button", "image/window_control_max_mousedown.bmp");
}
}

function maxMouseOver() {
if (clickInWindow == true) {
if (maxSize == true) {
changeImage("top_max_button", "image/window_control_resile_mouseon.bmp");
}
else {
changeImage("top_max_button", "image/window_control_max_mouseon.bmp");
}
}
else {
if (maxSize == true) {
changeImage("top_max_button", "image/window_control_resile_blur.bmp");
}
else {
changeImage("top_max_button", "image/window_control_max_blur.bmp");
}
}
}

function maxMouseOut() {
if(clickInWindow == true) {
if (maxSize == true) {
changeImage("top_max_button", "image/window_control_resile_normall.bmp");
} else {
changeImage("top_max_button", "image/window_control_max_normall.bmp");
}
} else {
if (maxSize == true) {
changeImage("top_max_button", "image/window_control_resile_blur.bmp");
} else {
changeImage("top_max_button", "image/window_control_max_blur.bmp");
}
}
}


function showNormalOrMax(){
if (maxSize && adjust) {
maxSize = false;
changeWindowSize(oldTop, oldLeft, oldWidth, oldHeight, true);
} else {
showMaxSize();
}
}

function minMouseDown() {
changeImage("top_min_button", "image/window_control_min_mousedown.bmp");
}

function minMouseOver() {
if(clickInWindow == true) {
changeImage("top_min_button", "image/window_control_min_mouseon.bmp");
} else {
changeImage("top_min_button", "image/window_control_min_blur.bmp");
}
}

function minMouseOut() {
if(clickInWindow == true) {
changeImage("top_min_button", "image/window_control_min_normall.bmp");
} else {
changeImage("top_min_button", "image/window_control_min_blur.bmp");
}
}


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();

if (down && adjust && !maxSize) {
if(idName == "mywindow_rBottom_corner") {
curLeft = coor[0];
curWidth += oldLeft - curLeft;
curHeight = coor[1] - oldTop;
if(curWidth < 80) {
curLeft = oldLeft + oldWidth - 80;
}
} else if(idName == "mywindow_left_corner") {
curTop = coor[1];
curLeft = coor[0];
curWidth += oldLeft - curLeft;
curHeight += oldTop - curTop;
if(curHeight < 40) {
curTop = oldTop + oldHeight - 40;
}
if(curWidth < 80) {
curLeft = oldLeft + oldWidth - 80;
}
} else if(idName == "mywindow_right_corner") {
curTop = coor[1];
curWidth = coor[0] - curLeft;
curHeight = oldHeight + oldTop - curTop;
if(curHeight < 40) {
curTop = oldTop + oldHeight - 40;
}
} else if(idName == "mywindow_top") {
curTop = curTop + coor[1] - clickTopDivY;
curLeft = curLeft + coor[0] - clickTopDivX;
clickTopDivX = coor[0];
clickTopDivY = coor[1];
} else if(idName == "mywindow_right") {
curWidth = coor[0] - oldLeft;
} else if(idName == "mywindow_left") {
curLeft = coor[0];
curWidth += oldLeft - curLeft;
if(curWidth < 80) {
curLeft = oldLeft + oldWidth - 80;
}
} else if(idName == "mywindow_top_drag") {
curTop = coor[1];
curHeight += oldTop - curTop;
if(curHeight < 40) {
curTop = oldTop + oldHeight - 40;
}
} else if(idName == "mywindow_bottom_drag"){
curHeight = coor[1] - oldTop;
} else {
// drag right corner of window
curWidth = coor[0] - oldLeft;
curHeight = coor[1] - oldTop;
}
if(curWidth < 80) {
curWidth = 80;
}

if(curHeight < 40) {
curHeight = 40;
}

changeWindowSize(curTop, curLeft, curWidth, curHeight, true);
}
}

this.end = function(idName) {
down = 0;
document.getElementById(idName).releaseCapture();
}
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/111784.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号