很常见的广告展示形式。浏览器打开页面的瞬间,从顶部弹出广告,3-5秒 后自动收起来。
<!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 name="Generator" content="NO" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<title>顶部伸缩广告</title>
</head>
<body>
<center>
<script type="text/javascript">
var intervalId = null;
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){
this.stayTime=nStayTime*1000 || 3000;
this.maxHeigth=nMaxHth || 460; //伸到最大的高度
this.minHeigth=nMinHth || 0; //缩到最小的告诉
this.state=sState || "down" ;
var obj = document.getElementById(id);
if(intervalId != null)window.clearInterval(intervalId);
function openBox(){
var h = obj.offsetHeight;
obj.style.height = ((this.state == "down") ? (h + 20) : (h - 20))+"px";
if(obj.offsetHeight>this.maxHeigth){
window.clearInterval(intervalId);
intervalId=window.setInterval(closeBox,this.stayTime);
}
if (obj.offsetHeight<this.minHeigth){
window.clearInterval(intervalId);
obj.style.display="none";
}
}
function closeBox(){
slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);
}
intervalId = window.setInterval(openBox,30);
}
</script>
<!--控制 #MyMoveAd的高度可以控制缩到最小的时候的广告高度-->
<div id="MyMoveAd" style="height:5px;overflow:hidden;">
<a href="http://www.tg4s.com/" target="_blank"><img src="http://www.tg4s.com/templets/ad/xtl.jpg" border="0" /></a>
</div>
<script type="text/javascript">
<!--
slideAd('MyMoveAd',2); //伸展后停留的时间
-->
</script>
</center>
<div style="width:100%; margin:0px auto; font-size:36px; text-align:center; background-color:#36F">这里是 正文</div>
</body>
</html>
兼容主流所有浏览器。
