首页头部下拉广告设计(javascript)

加在Head中
<script type="text/javascript" language="javascript">
var intervalId = null;
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){
this.stayTime=nStayTime*1000 || 3000;
this.maxHeigth=nMaxHth || 330//广告最大高度
this.minHeigth=nMinHth || 1;
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 +5 ) : (h - 5))+"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,2);
}

</script>

加在Body下面
<div id="slideAD" style="overflow: hidden; height: 0; padding-left:10px; width:985px"><div id="hd"><img src="/img/close.gif" alt="关闭" onclick="slideAd('slideAD',5,'up');return false;"/></div>
<div align="center">这里插入相应的图片或flash</script></div>
</div>

设置当页面完全加载之后执行,10MS 检测一次
<script type="text/javascript">

  
<!--   
  
function   chk(){   
  (
this.document.readyState=="complete")?slideAd('slideAD',8):setTimeout('chk()',10);   
  }
   
  chk();   
  
//-->   


</script>

posted @ 2008-01-17 09:36  kingboy  阅读(1467)  评论(0编辑  收藏  举报