关闭

javascript实现仿网易

484人阅读 评论(0) 收藏 举报

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Hello</title>
<meta name="author" content="年华@Master8.NET" />
<style>
body { background-color:#FFFFFF; margin:0;}
li,td,div,body {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #333333; }
</style>
</head>
<body>
<script type="text/javascript">//必须body中引用
var width=300;
var height=200;
var bgcolor="#EEEEEE";//半透明窗口背景色DivMid
var trans=90;
var body = document.body;
var bodyWidth = parseInt((body.scrollWidth<body.clientWidth)?body.clientWidth:body.scrollWidth);
var bodyHeight = body.clientWidth; parseInt((body.scrollHeight<body.clientHeight)?body.clientHeight:body.scrollHeight);
var clientWidth=body.clientWidth;
var clientHeight=body.clientHeight;
//开始创建DivTop 最上信息层
var DivTop        = document.createElement("div");
with(DivTop.style)
{
        display = "none";
        zIndex = 3;
        position = "absolute";
        border = "0px";       
}
DivTop.id = "Div3";

body.appendChild(DivTop);
DivTop.innerHTML = "<table cellspacing=/"0/" cellpadding=/"0/" style=/"width:"+width+"px;border:#0051E5 1px solid;background:#FFFFFF;/"><tr><td style=/"background:#0051E5;color:#FFFFFF;font-size:13px;height:18px;/"><span style=/"float:right/"><a href=/"javascript:Close();/" style=/"color:#FFFFFF;text-decoration:none;background:#CC4332;display:block;padding:1px;height:14px;width:14px;font-size:12px;overflow:hidden;/">×</a></span> 信 息 提 示</td></tr><tr><td style=/"line-height:180%;padding:2px;/">  Master8.NET</td></tr></table>";

//开始创建DivMid 中间半透明层
var DivMid        = document.createElement("div");
with(DivMid.style)
{
        display = "none";
        zIndex = 2;
        position = "absolute";
        height = "100%";
        width = "100%";
        top = 0;
        left = 0;
        border = "0px";
        backgroundColor = bgcolor;
}
DivMid.id = "Div2";
body.appendChild(DivMid);

function $(Id) { return document.getElementById(Id); }
function isIE()
{
        return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}

function center(win)//将主窗口置于网页正中
{
        var s = parseInt(body.scrollTop + clientHeight/2 - height/2);
        win.style.top = (s<body.scrollHeight-height)?s:body.scrollHeight;
        var s = parseInt(body.scrollLeft + clientWidth/2 - width/2);
        win.style.left = (s<body.scrollWidth-width)?s:body.scrollWidth;
}

function Open(){

        with(body.style)//完全锁定背景层
        {
                width = clientWidth;
                height = clientHeight;
                overflow = "hidden";
        }
        with($('Div2').style)
        {
                width = bodyWidth;
                height = bodyHeight;
                overflow = "hidden";
                display = "";
                if (isIE()){
                        filter = " Alpha(Opacity="+trans+")";
                }else{
                        opacity = trans/100;
                }
                       
        }
        with($('Div3').style)
        {
                display = "";               
        }
        center($('Div3'));
       
}

function Close(){
        with(body.style)
        {
                width = bodyWidth;
                height = bodyHeight;
                overflow = "auto";
        }
        with($('Div2').style)
        {
                display = "none";
        }
        with($('Div3').style)
        {
                display = "none";                       
        }
       
}
Open();
</script>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<p align="center"><a href="javascript:Open()">Click To Open</p>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</html>
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:33452次
    • 积分:461
    • 等级:
    • 排名:千里之外
    • 原创:8篇
    • 转载:25篇
    • 译文:1篇
    • 评论:5条
    文章分类
    最新评论