广告上下移动

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<title>仿163首页图片收缩效果</title>
<style>
#top{
 position:relative;  /* 相当定位*/
 }
#content{
 position:absolute;   /* 绝对定位*/
 }
</style>
</head>

<body style="margin:0px 0px" onLoad="moveDown()">
<div id="top" style="width:100%; height:220px; background-color:#C00;">广告部分<br>
广告部分<br>广告部分<br>广告部分<br>广告部分<br>广告部分<br>广告部分<br>广告部分<br>广告部分<br>广告部分<br>
</div>
<div id="content" style="width:100%; height:300px; background-color:#9C3">网页内容部分</div>


</body>
</html>
<script language="javascript" type="text/javascript">
 //定义一个步长
 var h=0;  //定义要移动的距离
 var maxheight=100;
 var st;
 var top=document.getElementById("top");
 //初始使  设置top为隐藏
 
 //定义让广告部分展开
 function moveDown(){
  top.style.display="none";
  //累加
  h+=2;
  //设置层显示
  //设置高度等于累加的值
  top.style.height=h;
  top.style.display="block";
  if(h<=maxheight){
   
   st=setTimeout("moveDown()",50);
   
   }else{
     clearTimeout(st);
     st=setTimeout("moveUp()",3000);
 
    }
  }
 //定义让广告部分收缩
 function moveUp(){
  //累  减
  h-=2;
  
  //设置层显示
  //设置高度等于;累减的值
  top.style.height=h;
  //alert(h);
  top.style.display="block";
  if(h<=0){
   //如果小于0  隐藏
   top.style.display="none";
   clearTimeout(st);
   }else{
    //如果H 大于0 继续收缩
    st=setTimeout("moveUp()",10);
    }
  
  }
  
</script>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值