弹出层,使之居于屏幕中间的代码。

来源:互联网 发布:jsbridge 实现网络请求 编辑:程序博客网 时间:2024/04/29 17:09

第一种

<body>
<center>
<div id="adv_1" style="width:200px; height:200px; background-color:#CCCC99; position:absolute; left:0px; top:0px;"></div>
<div style="width:768px; height:800px; background-color:#FFFF99;"></div>
<script language="javascript">
var adv=document.getElementById("adv_1");
adv.style.left=(this.screen.width-parseInt(adv.style.width.replace("px","")))/2+"px";
adv.style.top=(this.screen.height-parseInt(adv.style.height.replace("px","")))/2-100+"px";
    function hide_div()
{
   adv.style.display="none";
}
    setTimeout("hide_div()",2000);
</script>
</center>
</body>

第二种

<body>
<center>
<div id="adv_1" style="width:200px; height:200px; background-color:#CCCC99; display:none; position:absolute; left:0px; top:0px;"></div>
<div style="width:768px; height:800px; background-color:#FFFF99;"></div>
<script language="javascript">
    function show_div()
{
     var adv=document.getElementById("adv_1");
   adv.style.left=(this.screen.width-parseInt(adv.style.width.replace("px","")))/2+"px";
   adv.style.top=(this.screen.height-parseInt(adv.style.height.replace("px","")))/2-100+"px";
   adv.style.display="block";
}
function hide_div()
{
     var adv=document.getElementById("adv_1");
   adv.style.display="none";
}
    show_div();
setTimeout("hide_div()",5000);
</script>
</center>
</body>

第三种

<body style="margin:0px;">
<center>
<div id="adv_1" style="width:350px; height:200px; background-color:#CCCC99; display:none; position:absolute; left:0px; top:0px;"><img src="pic/1.gif" border="0" width="350" height="200" /></div>
<div style="width:768px; height:800px; background-color:#FFFF99;"><img src="pic/5.jpg" border="0" /></div>
<script language="javascript">
    function show_div()
{
     var adv=document.getElementById("adv_1");
   adv.style.left=(this.screen.width-parseInt(adv.style.width.replace("px","")))/2+"px";
   adv.style.top=(this.screen.height-parseInt(adv.style.height.replace("px","")))/2-150+"px";
   adv.style.display="block";
}
function hide_div()
{
     var adv=document.getElementById("adv_1");
   adv.style.display="none";
}
    show_div();
setTimeout("hide_div()",4000);
</script>
</center>
</body>