向上循环滚动的图片展示效果

<style type="text/css">
#ad{
 position:absolute;
 width:150px;
 height:200px;
 border:1px solid #000;
 overflow:hidden;
}
#ad ul{
 position:absolute;
 list-style-type:none;
 margin:0;
 padding:0;
}
</style>
<script language="javascript">
var ad = {
 o:null,      // 存放滚动的UL
 cloneImg:null,      //克隆UL的第一个图片
 adY:0,      //滚动值
 distan:0,     //每个图片的高度
 init:function(obj){
  if(!obj.style.top){
   obj.style.top = '0px';
  }
  this.cloneImg = obj.firstChild.cloneNode(true);     //克隆第一个节点
  if(this.cloneImg.nodeType == 3) this.cloneImg = obj.firstChild.nextSibling.cloneNode(true);   //除IE外第一个节点为文本节点,这里做点调整,让克隆节点还是指向第一个元素
  obj.appendChild(this.cloneImg);   //让克隆的节点放入最后
  this.adY = parseInt(obj.style.top);
  this.o = obj;
  this.distan = this.cloneImg.offsetHeight;   //获取高度
  this.moveCtrl();
 },
 moveCtrl:function(){
  if(Math.abs(this.adY) == this.o.offsetHeight - this.distan) this.adY = 0;  //当到达底部,让滚动直接跳回最上面
  if(Math.abs(this.adY)%this.distan==0){
   setTimeout('ad.moveCtrl()',5000);   //对每个图片做停留,也就是延迟函数的循环
  } else {
   setTimeout('ad.moveCtrl()',10);    //运动循环
  }
  --this.adY;
  ad.o.style.top = this.adY + 'px';
 }
}
window.onload = function(){
 var obj = document.getElementById('adul');
 ad.init(obj);   //直接把UL放入类里,就可以用了,类已基本封装好
}
</script>
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<div id="ad">
  <ul id="adul">
    <li><img src="http://www.zzsky.cn/effect/images/huandeng1.jpg" width="150" height="200"></li>
    <li><img src="http://www.zzsky.cn/effect/images/huandeng2.jpg" width="150" height="200"></li>
    <li><img src="http://www.zzsky.cn/effect/images/huandeng3.jpg" width="150" height="200"></li>
    <li><img src="http://www.zzsky.cn/effect/images/huandeng4.jpg" width="150" height="200"></li>
    <li><img src="http://www.zzsky.cn/effect/images/huandeng5.jpg" width="150" height="200"></li>
  </ul>
</div>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值