[收藏]JS模拟窗口

None.gif <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
None.gif
< html  xmlns ="http://www.w3.org/1999/xhtml" >
None.gif
< head >
None.gif
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312"   />
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif
InBlock.gif
function $() 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var arr=new Array();
InBlock.gif    
for (var i=0; i < arguments.length; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var aa=arguments[i];
InBlock.gif        
if(typeof(aa)=='string')
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            aa
=document.getElementById(aa);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
if(arguments.length==1)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return aa;
ExpandedSubBlockEnd.gif        }

InBlock.gif        arr.push(aa);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return arr;
ExpandedSubBlockEnd.gif}

InBlock.gif
function Cmsgbox()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
this.title=null;
InBlock.gif    
this.message=null;
InBlock.gif    
this.left=[];
InBlock.gif    
this.top=[];
InBlock.gif    
this.isminibox=[];
InBlock.gif    
this.width=[];
InBlock.gif    
this.id=0;
InBlock.gif    
this.hover='orange';
InBlock.gif    
this.normal='slategray';
InBlock.gif    
this.dragenable=false;
InBlock.gif    
this.x=0;
InBlock.gif    
this.y=0;
InBlock.gif    
this.curindex=100;
InBlock.gif    
this.actindex=null;
InBlock.gif    
this.modal=true;
InBlock.gif    
this.bgdivobj=null;
ExpandedSubBlockEnd.gif}

InBlock.gifCmsgbox.prototype.subwin
=function(msg,fcallback,tit,w,l,t,modal,type)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var buttoncss="width:69px;height:20px;color:#333;cursor:hand;";
InBlock.gif    
if(type==2)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if(modal=="undefined"||modal==null)
InBlock.gif            modal
=false;
InBlock.gif        
this.isminibox[this.id]=false;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
this.basemsg(tit,msg,w,l,t,modal);
InBlock.gif    
var str="<div id='"+this.id+"csubwin' οnmοusedοwn='Cmgbox.totop(this)' style='z-index:"+(this.curindex++)+";background-color:white;position:absolute;border:2px solid "+this.normal+";left:"+this.left[this.id]+"px;top:"+this.top[this.id]+"px;width:"+this.width[this.id]+"px;' >";
InBlock.gif    str
+="<div style='padding-bottom:2px;background-color:"+this.normal+";width:100%;height:16px;color:white;' ";
InBlock.gif    str
+="οnmοusedοwn='Cmgbox.begindrag(this)' οnmοusemοve='Cmgbox.ondrag(this)' οnmοuseup='Cmgbox.enddrag(this)' ";
InBlock.gif    
if(type==2)
InBlock.gif        str
+="οndblclick='Cmgbox.minibox(this.childNodes(1))'";
InBlock.gif    str
+="><div style='float:left;height:16px;overflow:hidden;margin:0px;padding:4px 0px 0px 5px;width:"+(this.width[this.id]-2*14-5)+";'>"+this.title+"</div>";
InBlock.gif    
if(type==2)
InBlock.gif        str
+="<span style='width:14px;font-family:webdings;cursor:hand;' οnclick='Cmgbox.minibox(this)'>0</span><span style='width:14px;font-family:webdings;cursor:hand;' οnclick='Cmgbox.closediv(this)'>r</span>";
InBlock.gif    str
+="</div><div style='margin:10px 5px 10px 10px;word-break:break-all;'>"+this.message+"</div>";
InBlock.gif    
if(type==0||type=="undefinded"||type==null||type==""||type==1)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        typestr
="<input type='button' style='"+buttoncss+"' id='boxyes' value='确 定' />";
InBlock.gif        
if(type==1)
InBlock.gif            typestr
+="&nbsp;&nbsp;&nbsp;<input type='button' style='"+buttoncss+"' value='取 消' οnclick='Cmgbox.closediv(this)' />";
InBlock.gif        str
+="<div style=text-align:right;margin:0px;padding:7px;padding-right:15px;background:#ccc;'>"+typestr+"</div></div>";
ExpandedSubBlockEnd.gif    }

InBlock.gif    
if(this.modal)
InBlock.gif        
this.showbgdiv(this.curindex-2);
InBlock.gif    
this.id++;
InBlock.gif    document.body.insertAdjacentHTML(
"beforeEnd",str);
InBlock.gif    
if(type!=2)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        $(
"boxyes").focus();
InBlock.gif        $(
"boxyes").onclick=function()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Cmgbox.closediv(
this);
InBlock.gif            
if(fcallback)
InBlock.gif                fcallback();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gifCmsgbox.prototype.showbgdiv
=function(zindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var swidth,sheight;
InBlock.gif    swidth
=document.body.offsetWidth+document.body.offsetLeft*2;
InBlock.gif    
if(document.body.clientHeight<screen.height)
InBlock.gif        sheight
=screen.height;
InBlock.gif    
else
InBlock.gif        sheight
=document.body.clientHeight+document.body.offsetTop*2;
InBlock.gif    
var bgobj=document.createElement("div");
InBlock.gif    bgobj.setAttribute('id','bgdiv');
InBlock.gif    bgobj.style.position
="absolute";
InBlock.gif    bgobj.style.top
="0px";
InBlock.gif    bgobj.style.background
="#ccc";
InBlock.gif    bgobj.style.filter
="progid:dximagetransform.microsoft.alpha(style=3,opacity=25,finishopacity=75)";
InBlock.gif    bgobj.style.left
="0px";
InBlock.gif    bgobj.style.width
=swidth;
InBlock.gif    bgobj.style.height
=sheight;
InBlock.gif    bgobj.style.zIndex 
= zindex;
ExpandedSubBlockStart.gifContractedSubBlock.gif    bgobj.oncontextmenu
=function()dot.gif{return false;}
ExpandedSubBlockStart.gifContractedSubBlock.gif    bgobj.ondragstart
=function()dot.gif{return false;}
ExpandedSubBlockStart.gifContractedSubBlock.gif    bgobj.onselectstart
=function()dot.gif{return false;}
InBlock.gif    document.body.appendChild(bgobj);
InBlock.gif    
this.bgdivobj=bgobj;
ExpandedSubBlockEnd.gif}

InBlock.gif
////关闭窗口
InBlock.gif
Cmsgbox.prototype.closediv=function(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
if(this.modal)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        document.body.removeChild(
this.bgdivobj);
InBlock.gif        
this.bgdivobj=null;
InBlock.gif        
this.modal=false;
ExpandedSubBlockEnd.gif    }

InBlock.gif    obj.parentNode.parentNode.removeNode(
true);
ExpandedSubBlockEnd.gif}

InBlock.gif
//使窗口出现在最顶端/
InBlock.gif
Cmsgbox.prototype.totop=function(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
this.actindex=this.curindex-1;
InBlock.gif    
if(obj.style.zIndex<this.actindex)
InBlock.gif        obj.style.zIndex
=this.curindex++;
ExpandedSubBlockEnd.gif}

InBlock.gif
/////开始拖动///
InBlock.gif
Cmsgbox.prototype.begindrag=function(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
if(event.button==1)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
this.dragenable=true;
InBlock.gif        obj.setCapture();
InBlock.gif        
var box=obj.parentNode;
InBlock.gif        
this.x=event.clientX;
InBlock.gif        
this.y=event.clientY;
InBlock.gif        box.style.borderColor
=this.hover;
InBlock.gif        obj.style.backgroundColor
=this.hover;
InBlock.gif        box.style.filter
="progid:DXImageTransform.Microsoft.shadow(direction=135,color=#8E8E8E,strength=5)";
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gif
///拖动中
InBlock.gif
Cmsgbox.prototype.ondrag=function(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
if(this.dragenable)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var box=obj.parentNode;
InBlock.gif        
var i=parseInt(box.id);
InBlock.gif        
var boxleft=event.clientX-this.x+this.left[i];
InBlock.gif        
var boxtop=event.clientY-this.y+this.top[i];
InBlock.gif        
if(boxleft>0&&boxleft+this.width[i]<(document.body.offsetWidth+document.body.offsetLeft*2))
InBlock.gif            box.style.pixelLeft
=boxleft;
InBlock.gif        
if(boxtop>0)
InBlock.gif            box.style.pixelTop
=boxtop;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gif
//结束拖动/
InBlock.gif
Cmsgbox.prototype.enddrag=function(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
if(this.dragenable)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var box=obj.parentNode;
InBlock.gif        
var i=parseInt(box.id);
InBlock.gif        
this.dragenable=false;
InBlock.gif        box.style.borderColor
=this.normal;
InBlock.gif        obj.style.backgroundColor
=this.normal;
InBlock.gif        
this.left[i]=box.style.pixelLeft;
InBlock.gif        
this.top[i]=box.style.pixelTop;
InBlock.gif        box.style.filter
="";
InBlock.gif        obj.releaseCapture();
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gif
/////窗口最小化///
InBlock.gif
Cmsgbox.prototype.minibox=function(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var title=obj.parentNode;
InBlock.gif    
var i=parseInt(title.parentNode.id);
InBlock.gif    
if(this.isminibox[i]=!this.isminibox[i])
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        title.nextSibling.style.display
="none";
InBlock.gif        obj.innerHTML
="2";
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        title.nextSibling.style.display
="";
InBlock.gif        obj.innerHTML
="0";
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gifCmsgbox.prototype.basemsg
=function(tit,msg,w,l,t,modal)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
this.title=tit||"系统消息";
InBlock.gif    
this.message=msg;
InBlock.gif    
if(modal=="undefined"||modal==null)
InBlock.gif        modal
=true;
InBlock.gif    
if(w=="undefined"||w==null||w=="")
InBlock.gif        w
=300;
InBlock.gif    
if(l=="undefined"||l==null||l=="")
InBlock.gif        l
=parseInt((document.body.clientWidth-w)/2);
InBlock.gif    
if(t=="undefined"||t==null||t=="")
InBlock.gif        t
=100+document.body.scrollTop;
InBlock.gif    
this.left[this.id]=l;
InBlock.gif    
this.top[this.id]=t;
InBlock.gif    
this.width[this.id]=w;
InBlock.gif    
this.modal=modal;
ExpandedSubBlockEnd.gif}

InBlock.gif
/////实例化/
InBlock.gif
var Cmgbox=new Cmsgbox();
ExpandedSubBlockStart.gifContractedSubBlock.gifwindow.subwin
=function(msg,tit,w,l,t,modal)dot.gif{Cmgbox.subwin(msg,function()dot.gif{},tit,w,l,t,modal,2);}    //跳出子窗口 例:window.subwin(标题,内容,宽,X坐标,Y坐标,是否模态显示); (默认为非模态)
ExpandedSubBlockStart.gifContractedSubBlock.gif
window.msgbox=function(msg,fcallback,tit,type,modal)dot.gif{return Cmgbox.subwin(msg,fcallback,tit,"","","",modal,type);}//跳出模态选框 例:window.msgbox(标题,内容,类型选择,是否模态显示);(type=0:alert; type=1:confirm)
None.gif
</ script >
None.gif
< title > 无标题文档 </ title >
ExpandedBlockStart.gifContractedBlock.gif
< style > dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gifbody
{dot.gif}{
InBlock.gif    font-size
:12px;
ExpandedBlockEnd.gif
}

None.gif
</ style >
None.gif
</ head >
None.gif
None.gif
< body >
None.gif    
< href ="javascript:window.subwin('tit后。当然也之页全部html标签之后你已经试过放在这里,但是发现根本不起作用,这就涉及到下一个要注意的问题了df可能是发现根本不起作用,这就涉及到下一个要注意的问题了。<br><br>2、Build函数的最后,你是通过insertAdjacentHTML()方法把生成的代码放在了网le','title')" > 跑出一个框 </ a >
None.gif    
< href ="javascript:window.subwin('你已经l标签之后你已经试过所以应该把对无法获取,方,也就是xWinxx赋值这个工作放在窗口第一次初始化完成的地放在这里,但是发现根本不起作用,这就涉及到下一个要注意的问试过放在这里','标题')" > 跑出一个框 </ a >
None.gif    
< href ="javascript:window.subwin('放在build语句之后。当然也可能是发现根本不起作用,这就涉及到下一个要注意的问题了。<br><br>2、Build函数的最后,你是通过insertAdjacentHTML()方法把生成的代码放在了网页全部html标签之后你已经试过放在这里,但是发现根本不起作用,这就涉及到下一个要注意的问题了了网页全部html标','子窗口',600)" > 跑出一个框 </ a >
None.gif    
< href ="javascript:window.subwin('页全部htfsdfs导致无法获取,所以应该把对xx赋值这个工作放在窗口第一次初始化完成的地方,也就是xWin函数中,this.b代码放在了网页全部html标签之后你已经试过ml','要注意的问题了df')" > 跑出一个框 </ a >
None.gif    
< href ="javascript:window.msgbox('sdfsdfsdfsdfs导致无法获取,所以应该把对xx赋值这个工作放在窗口第一次初始化完成的地方,也就是xWin函数中,this.build语句之后把生成的代页全部html标签之后你已经试过放在这里,但是发现根本不起作用,这就涉及到下一个要注意的问题了df',function(){alert(true)},'码放在了网',1)" > 警告框 </ a >
None.gif
</ body >
None.gif
</ html >
None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值