网页左右两侧居中的对联广告代码

发布时间:2015-2-19 18:32:43 作者:小五 点击:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#left{ width:200px;height:450px; position:absolute; left:0px; background:red; border:1px #000 solid}
#right{width:200px;height:450px; position:absolute; right:0px; background:blue; border:1px #000 solid}
#x,#y{ width:10px; height:10px;position:absolute;right:0px; top:0px;}
</style>
<script>
window.onload=window.onscroll=function()
{
var oLeft = document.getElementById("left");
var oRight = document.getElementById("right");
var scrollY=document.documentElement.scrollTop||document.body.scrollTop;
var clientH = document.documentElement.clientHeight;
var oCloseX =document.getElementById("x")
var oCloseY =document.getElementById("y")
oLeft.style.top=(clientH-oLeft.offsetHeight)/2+scrollY+"px";
oRight.style.top=(clientH-oRight.offsetHeight)/2+scrollY+"px";
oCloseX.onclick=function()
{
this.parentNode.parentNode.removeChild(this.parentNode);
}
}
</script>
</head>
<body style="height:2000px;">
<div id="left">
<div id="x">x</div>
</div>
<div id="right">
<div id="y">x</div>
</div>
</body>
</html>

留言列表

发表留言:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。