百度空间的popup效果分析第3/3页
更新时间:2008年10月10日 23:01:44 作者:
自从用firefox浏览器以来,就几乎养成了一个习惯,就想用WebDeveloper把一些漂亮网站的js包括css给down下来分析一下,用来学习。
//让弹出窗口居中显示
middle:function ()
{
if(!this.config.isBackgroundCanClick)
G('dialogBoxBG').style.display='';
var oDialog=G('dialogBox');
oDialog['style']['position']="absolute";
oDialog['style']['display']='';
var sClientWidth=document.body.clientWidth;
var sClientHeight=document.body.clientHeight;
var sScrollTop=document.body.scrollTop;
//alert("document.body.clientWidth = " + sClientWidth + "\ndocument.body.clientHeight" +sClientHeight);
var sleft=(document.body.clientWidth/2)-(oDialog.offsetWidth/2);
var iTop=-80+(sClientHeight/2+sScrollTop)-(oDialog.offsetHeight/2);
var sTop=iTop>0?iTop:(sClientHeight/2+sScrollTop)-(oDialog.offsetHeight/2);
//alert("var iTop=-80+(sClientHeight/2+sScrollTop)-(oDialog.offsetHeight/2);\n" + "sClientHeight is " + sClientHeight + "\nsScrollTop is " + sScrollTop);
//alert("iTop is " + iTop);
if(sTop<1)
sTop="20";
if(sleft<1)
sleft="20";
oDialog['style']['left']=sleft;
oDialog['style']['top']=sTop;
//alert("sleft is " + sleft);
//alert("sTop is " + sTop);
},
//刷新页面,并关闭当前弹出窗口
reset:function ()
{
if(this.config.isReloadOnClose)
{
top.location.reload();
};
this.close();
},
//关闭当前弹出窗口
close:function ()
{
G('dialogBox').style.display='none';
if(!this.config.isBackgroundCanClick)
G('dialogBoxBG').style.display='none';
if(this.config.isShowShadow)
G('dialogBoxShadow').style.display='none';
G('dialogBody').innerHTML='';
this.showSome();
},
//隐藏someHiddenTag和someHiddenEle中的所有元素
hiddenSome:function ()
{
//隐藏someHiddenTag中的所有元素
var tag=this.info.someHiddenTag.split(",");
if(tag.length==1&&tag[0]=="")
{
tag.length=0;
}
for(var i=0;i<tag.length;i++)
{
this.hiddenTag(tag[i]);
};
//隐藏someHiddenEle中的所有逗号分割的ID的元素
var ids=this.info.someHiddenEle.split(",");
if(ids.length==1&&ids[0]=="")
ids.length=0;
for(var i=0;i<ids.length;i++)
{
this.hiddenEle(ids[i]);
};
//改变顶部和底部的div的id值为弹出状态的id值,祥见space的实现
space("begin");
},
//隐藏一组元素
hiddenTag:function (tagName)
{
var ele=document.getElementsByTagName(tagName);
if(ele!=null)
{
for(var i=0;i<ele.length;i++)
{
if(ele[i].style.display!="none"&&ele[i].style.visibility!='hidden')
{
ele[i].style.visibility='hidden';
this.someToHidden.push(ele[i]);
};
};
};
},
//隐藏单个元素
hiddenEle:function (id)
{
var ele=document.getElementById(id);
if(typeof(ele)!="undefined"&&ele!=null)
{
ele.style.visibility='hidden';
this.someToHidden.push(ele);
}
},
//将someToHidden中保存的隐藏元素全部显示
//并恢复顶部和底部的div为原来的id值
showSome:function ()
{
for(var i=0;i<this.someToHidden.length;i++)
{
this.someToHidden[i].style.visibility='visible';
};
space("end");
}
};
//********************************************************Dragdrop类(拖拽动作)************************************************************
var Dragdrop=new Class();
Dragdrop.prototype={
initialize:function (width,height,shadowWidth,showShadow,contentType)
{
this.dragData=null;
this.dragDataIn=null;
this.backData=null;
this.width=width;
this.height=height;
this.shadowWidth=shadowWidth;
this.showShadow=showShadow;
this.contentType=contentType;
this.IsDraging=false;
this.oObj=G('dialogBox');
Event.observe(G('dialogBoxTitle'),"mousedown",this.moveStart.bindAsEventListener(this),false);
},
moveStart:function (event)
{
this.IsDraging=true;
if(this.contentType==1)
{
G("iframeBG").style.display="";
G("iframeBG").style.width=this.width;
G("iframeBG").style.height=this.height;
};
Event.observe(document,"mousemove",this.mousemove.bindAsEventListener(this),false);
Event.observe(document,"mouseup",this.mouseup.bindAsEventListener(this),false);
Event.observe(document,"selectstart",this.returnFalse,false);
this.dragData={x:Event.pointerX(event),y:Event.pointerY(event)};
this.backData={x:parseInt(this.oObj.style.left),y:parseInt(this.oObj.style.top)};
},
mousemove:function (event)
{
if(!this.IsDraging)
return ;
var iLeft=Event.pointerX(event)-this.dragData["x"]+parseInt(this.oObj.style.left);
var iTop=Event.pointerY(event)-this.dragData["y"]+parseInt(this.oObj.style.top);
if(this.dragData["y"]<parseInt(this.oObj.style.top))
iTop=iTop-12;
else if(this.dragData["y"]>parseInt(this.oObj.style.top)+25)
iTop=iTop+12;
this.oObj.style.left=iLeft;
this.oObj.style.top=iTop;
if(this.showShadow)
{
G('dialogBoxShadow').style.left=iLeft+this.shadowWidth;
G('dialogBoxShadow').style.top=iTop+this.shadowWidth;
};
this.dragData={x:Event.pointerX(event),y:Event.pointerY(event)};
document.body.style.cursor="move";
},
mouseup:function (event)
{
if(!this.IsDraging)
return ;
if(this.contentType==1)
G("iframeBG").style.display="none";
document.onmousemove=null;
document.onmouseup=null;
var mousX=Event.pointerX(event)-(document.documentElement.scrollLeft||document.body.scrollLeft);
var mousY=Event.pointerY(event)-(document.documentElement.scrollTop||document.body.scrollTop);
if(mousX<1||mousY<1||mousX>document.body.clientWidth||mousY>document.body.clientHeight)
{
this.oObj.style.left=this.backData["x"];
this.oObj.style.top=this.backData["y"];
if(this.showShadow)
{
G('dialogBoxShadow').style.left=this.backData.x+this.shadowWidth;
G('dialogBoxShadow').style.top=this.backData.y+this.shadowWidth;
};
};
this.IsDraging=false;
document.body.style.cursor="";
Event.stopObserving(document,"selectstart",this.returnFalse,false);
},
returnFalse:function ()
{
return false;
}
};
将上面对popup.js文件做个引用,下面是对这个js文件进行测试的html页面的代码。你可以回去很方便的测试。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PopUpTest.aspx.cs" Inherits="PopUpTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript" src="Scripts/popup.js"></script>
<script type="text/javascript">
function ShowIframe()
{
var pop=new Popup({ contentType:1,isReloadOnClose:false,width:400,height:500});
pop.setContent("contentUrl","Default.aspx");
pop.setContent("title","iframe框架示例");
pop.build();
pop.show();
}
function ShowHtmlString()
{
var strHtml = "<table border=1 style='width:90%; text-align:center;'><tr style='height:40px'><td>ds</td><td>dads</td></tr><tr style='height:40px'><td>dadas</td><td>dasd</td></tr><tr style='height:40px'><td>dadasd</td><td>dsadads</td></tr></table>";
var pop=new Popup({ contentType:2,isReloadOnClose:false,width:340,height:300});
pop.setContent("contentHtml",strHtml);
pop.setContent("title","html字符串示例");
pop.build();
pop.show();
}
function ShowConfirm()
{
var pop=new Popup({ contentType:3,isReloadOnClose:false,width:340,height:80});
pop.setContent("title","confirm对话框示例");
pop.setContent("confirmCon","confirm对话框的内容");
pop.setContent("callBack",ShowCallBack);
pop.setContent("parameter",{id:"divCall",str:"点击确定后显示的字符串",obj:pop});
pop.build();
pop.show();
}
function ShowAlert()
{
var pop=new Popup({ contentType:4,isReloadOnClose:false,width:340,height:80});
pop.setContent("title","alert警告框示例");
pop.setContent("alertCon","alert对话框的内容");
pop.build();
pop.show();
}
function ShowCallBack(para)
{
var o_pop = para["obj"]
var obj = document.getElementById(para["id"]);
o_pop.close();
obj.innerText = para["str"];
}
</script>
</head>
<body style="text-align:center;">
<form id="form1" runat="server">
<div>
<a href="javascript:ShowIframe()">iframe框架示例</a>
<br />
<a href="javascript:ShowHtmlString()">html字符串示例</a>
<br />
<a href="javascript:ShowConfirm()">confirm对话框示例</a>
<br />
<a href="javascript:ShowAlert()">alert警告框示例</a>
</div>
<div id="divCall" style="width:300px; height:200px; background-color:#cccccc; color:Red; float:right;">
</div>
</form>
</body>
</html>
代码一堆一堆的啊!那个拖拽的不是很清楚怎么回事?上面的那个class函数也不清楚到底是怎么弄的。凡是没有写注释的地方,基本上就不是很明白。我找时间再分析分析吧!找时间把其它的注释也给写上。如果大家明白的,还请多多指教,越详细越好。
相关文章
javascript中Date()函数在各浏览器中的显示效果
本文给大家分享的是javascript中Date()函数在各浏览器中的显示效果,由于各大浏览器的兼容性问题,本文做了这个测试,希望有需要的小伙伴可以少走些弯路2015-06-06
最新评论