HTMl教程:实现网页左右两侧居中的对联广告代码
今天这篇文章给大家介绍一下网站中实现两侧广告代码的案例,下面我们一起来看看吧!
<!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>
有兴趣的朋友赶紧运用以上的代码试一试吧!
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |