对联广告相对页面始终垂直居中

<style>
#left{ width:100px;height:50px; position:absolute; left:0px; background-color:#FF0000}
#right{width:100px;height:50px; position:absolute; right:0px; background-color:#FF0000}
</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>
<div id="left">left</div>
<div id="right">right</div>

你可能感兴趣的:(对联广告相对页面始终垂直居中)