js弹出遮罩层

<!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>
<title></title>
<script>
function _(id) {
  return document.getElementById(id);
}
var ti = null;
function loading(){
    var tmd = 0;
    var x1 = document.documentElement.clientWidth; 
    var y1 = document.body.offsetHeight;
    var y2=document.documentElement.clientHeight;//整个页面的高度
    with(_("div1")){
       style.width=x1+"px";
       if(y2>y1){
       style.height=y2+"px";
       }else{
       style.height=y1+"px";
       }
       style.overflowX="hidden";
       style.overflowY="hidden";
       style.visibility="visible";
    }
    _("div1").style.left=0;
    _("div1").style.filter='Alpha(Opacity=0)';
    document.body.style.overflowX="hidden";
    document.body.style.overflowY="hidden";
    _("div2").style.top=parseInt(document.documentElement.scrollTop)+((document.documentElement.clientHeight-250)/2)+"px"; 
    _("div2").style.left="50%";
    _("div2").style.marginLeft="-190px"
    _("div2").style.visibility="visible";
    ti = setInterval("hei()",10);
}
var x = 0;
function hei(){
    x+=10;
    if(x<31){
        if(document.all){
            _("div1").style.filter='Alpha(Opacity='+x+')';
        }else{
            _("div1").style.opacity=""+x/100+"";    
        }
    }
}
function unload(){
_("div1").style.visibility="hidden";
_("div2").style.visibility="hidden";
clearInterval(ti);
x=0;
}
</script>
<style>
*{ 
    padding: 0; 
     margin: 0; 
}
div{
background-color:#fff;
}
#div1{
position:absolute;
visibility:hidden;
filter:alpha(opacity=70);
background-color:#a6a6a6;
z-index:9;
}
#div2{
position:absolute;
width:371px;
height:auto;
border:2px #aeddf1 solid;
visibility:hidden;
left:expression((body.clientWidth-300)/2);
background-color:#CCCCCC;
text-align:center;
z-index:10;
}
#top{
background-color:#eef7fe;
height:23px;
border-bottom:1px #aedef2 solid;
text-align:right;
}
</style>
</head>
<body>
<div id="div1" align="center"></div>
<div id="div2">
    <div id="top"><img src="http://www.wotuitui.com/images/close.gif" style="cursor:hand;" onClick="unload();" alt="点击关闭"/></div>
<div><br/><br/><br/>内容<br/><br/><br/><br/><br/></div>
</div>
<a href="javascript:loading();">打开</a>
</body>
</html>


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wanchong998/archive/2009/08/31/4501206.aspx

posted on 2010-12-15 10:26  woshilee  阅读(292)  评论(0)    收藏  举报

导航