<html>
<head>
<title>PortletWin</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<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;}
.win-function{
position:relative;
left:0;
width:12;
border-width:0px;
color:white;
font-family:webdings;
}
-->
</style>
<script language=JScript>
<!--
//可以打包为js文件;
var x0=0,y0=0; //鼠标位置
var x1=0,y1=0; //窗体位置
var offx=5,offy=5; //shadow和win的位差
var moveable=false; //mousemove
var xstart=false, ystart=false;
var hover='orange',normal='#336699';//color;
var index=10000;//z-index;
//拖动,参数obj可能为标题栏或窗体;
var win,shadow;
function getHandler(obj){
win = obj.parentNode;
shadow = win.nextSibling;
}
function startDrag(obj){//标识active
if (event.button==1){
obj.setCapture();
//定义对象;
getHandler(obj);
//记录鼠标和层位置;
x0 = event.clientX;
y0 = event.clientY;
x1 = parseInt(win.style.left);
y1 = parseInt(win.style.top);
//改变风格;
win.children[0].style.backgroundColor = hover;
win.style.borderColor = hover;
win.children[1].style.color = hover;
shadow.style.left = x1 + offx;
shadow.style.top = y1 + offy;
moveable = true;
}
}
function drag(obj){
if (moveable){
win.style.left = x1 + event.clientX - x0;
win.style.top = y1 + event.clientY - y0;
shadow.style.left = parseInt(win.style.left) + offx;
shadow.style.top = parseInt(win.style.top) + offy;
}
}
function stopDrag(obj){
getHandler(obj);
win.style.borderColor = normal;
win.children[0].style.backgroundColor = normal;
win.children[1].style.color = normal;
shadow.style.left = win.style.left;
shadow.style.top = win.style.top;
obj.releaseCapture();
obj.style.cursor = "default";
moveable = false;
}
//改变大小
function alterCursor(obj){
xstart = event.clientX >= parseInt(obj.style.left)+parseInt(obj.offsetWidth) - 5;
ystart = event.clientY >= parseInt(obj.style.top)+parseInt(obj.offsetHeight) + 20;
if (xstart && ystart){
obj.style.cursor = "se-resize";
}else if (xstart){
obj.style.cursor = "w-resize";
}else if (ystart){
obj.style.cursor = "s-resize";
}else{
obj.style.cursor = "default";
}
}
function startResize(obj){
alterCursor(obj);
if (xstart || ystart){
obj.fixedWidth = obj.offsetWidth;
obj.fixedHeight = obj.offsetHeight;
startDrag(obj);
}
}
function resize(obj){
if (moveable){
if (xstart){
var width = parseInt(obj.fixedWidth) + event.clientX - x0;
obj.style.width = Math.max(width, 0);
win.style.width = obj.offsetWidth + 2*2;
win.children[0].style.width = obj.offsetWidth;
}
if (ystart){
var height = parseInt(obj.fixedHeight) + event.clientY - y0;
obj.style.height = Math.max(height, 0);
win.style.height = obj.offsetHeight + 20 + 2*2;
}
drawIcons();
shadow.style.width = win.style.width;
shadow.style.height = win.style.height;
}
}
//获得焦点;
function getFocus(obj){
if (obj.style.zIndex!=index){
index = index + 2;
obj.style.zIndex = index;
obj.nextSibling.style.zIndex = index-1;
}
}
/**
* 最小化;
* obj:标题栏的一个小图标
*/
function min(obj){
var win = obj.parentNode.parentNode;
var shadow = win.nextSibling;
var win_title = obj.parentNode;
var win_body = win_title.nextSibling;
win.style.height = parseInt(win_title.style.height) + 2*2;
if (obj.innerHTML == "2"){ //还原
win.style.height = parseInt(win_body.style.height) + parseInt(win.style.height);
win_body.style.display = "block";
obj.innerHTML = "0";
}else{
obj.innerHTML = "2";
win_body.style.display = "none";
}
shadow.style.height = win.style.height;
}
//创建一个对象;
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(); //调用方法
}
//初始化;
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 + ";' "
+ "οnmοusedοwn='getFocus(this)'>"
//标题栏
+ "<div style='background-color:" + normal + ";"
+ "width:" + (this.width-2*2) + ";height:20;color:white;font-weight:bold' "
+ "οnmοusedοwn='startDrag(this)' οnmοuseup='stopDrag(this)' οnmοusemοve='drag(this)' "
+ "οndblclick='min(this.childNodes[1])'>"
+ "<span style='width:" + (this.width-2*12-4) + ";padding-left:3px;'>" + this.title + "</span>"
+ "<span class='win-function' οnclick='min(this)'>0</span>"
+ "<span class='win-function' οnclick='ShowHide()'>r</span>"
+ "</div>"
//窗体显示区域
+ "<div style='width:100%;height:" + (this.height-20-2*2) + ";left:"+this.left+";top="+(this.top-20-2)
+ ";background-color:white;line-height:14px;word-break:break-all;padding:3px;"
+ "' οnmοuseοver='alterCursor(this)' οnmοusedοwn='startResize(this)' οnmοusemοve='alterCursor(this);resize(this)' οnmοuseup='stopDrag(this)'>"
+ 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=30);'></div>"
document.body.insertAdjacentHTML("beforeEnd",str);
}
function drawIcons(){
var title = win.children[0];
while (title.children.length > 1){
title.removeChild(title.lastChild);
}
title.insertAdjacentHTML("beforeEnd","<span class='win-function' οnclick='min(this)'>0</span>");
title.insertAdjacentHTML("beforeEnd","<span class='win-function' οnclick='ShowHide()'>r</span>");
title.children[0].style.width = parseInt(title.style.width) - 24;
}
//显示隐藏窗口
function ShowHide(){
if (arguments.length > 0){
win = document.getElementById("xMsg"+arguments[0]);
}else{
win = event.srcElement.parentNode.parentNode;
}
var bdisplay = (win.style.display==null || win.style.display=="none") ? "block" : "none";
win.style.display = bdisplay;
win.nextSibling.style.display = bdisplay;
}
//-->
</script>
<script language='JScript'>
<!--
function initialize(){
var a = new xWin("1",160,200,200,200,"窗口1","xWin <br> A Cool Pop Div Window<br>Version:1.0<br>2002-8-13");
var b = new xWin("2",240,200,100,100,"窗口2","Welcome to visited my personal website:<br><a href=http://www14.brinkster.com/wildcity target=_blank>http://wildcity.126.com</a><br>and u can also sign my guestbook at:<br><a href=http://www14.brinkster.com/wildcity/gbook target=_blank>http://wildcity.126.com/gbook</a><br><br>thx!!! =)...");
var c = new xWin("3",200,160,250,50,"窗口3","Copyright by <a href='mailto:wildwind_zz@21cn.com'>Wildwind</a>!");
ShowHide("1");//隐藏窗口1
}
window.onload = initialize;
//-->
</script>
</head>
<body onselectstart='return false' οncοntextmenu='return false' >
<a οnclick="ShowHide('1');return false;" href="">窗口1</a>
<a οnclick="ShowHide('2');return false;" href="">窗口2</a>
<a οnclick="ShowHide('3');return false;" href="">窗口3</a>
</body>
</html>