带缓存的一个图片动态的上翻效果

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>图片滚动(仿惠惠网)</title>
  <meta name="Keywords" content="图片滚动(仿惠惠网)" />
  <meta name="Description" content="图片滚动(仿惠惠网)" />
  <style>* {margin:0;padding:0}</style>
  <!-- Jquery library -->
 
  <script type="text/javascript">
  window.οnlοad=function(){
   var oTab=document.getElementById("tab-wrap");
   var oList=oTab.getElementsByTagName("ul")[0];
   var aLi=oTab.getElementsByTagName("li");
   var aImg=oTab.getElementsByTagName("img");
   var aDiv=oTab.getElementsByTagName("div");
   var sWidth=aImg[0].offsetHeight;
   var index=i=0;
   var timer=playTimer=null;
   var bOrder=true;
   var aTmp=[];
   var aLib=[0];
   var aClor=[["#DF2526","#00B5E4"],["#AAC901","#DF2018"],["#07FFF1","#FF650F"],["#9670C3","#49BCFD"]];
   //
   for(i=0;i<aLi.length;i++){
    aTmp.push("<li></li>")
   }
   var oCount=document.createElement("ul");
   oCount.className="count";
   oCount.innerHTML=aTmp.join("");
   oTab.appendChild(oCount);
   //
   var aBtn=oTab.getElementsByTagName("ul")[1].getElementsByTagName("li");
   for(i=0;i<aBtn.length;i++){
    aBtn[i].index=i;
    aBtn[i].οnclick=function(){
     index=this.index;
     aLib.push(index);
     if(aLib.length>2){aLib.shift()};
     for(i=0;i<aBtn.length;i++){
      aBtn[i].className="";
      aLi[i].style.zIndex=100;
      aLi[i].style.display="none";
     }
     aBtn[index].className="current";
     aLi[index].style.zIndex=200;
     aLi[index].style.top=sWidth+"px";
     aLi[index].style.display="block";
     aLi[aLib[0]].style.display="block";
     aLi[index].style.background=aClor[index][0];
     aDiv[index].style.background=aClor[index][1];
     if(aLib[0]!=aLib[1]){
      showMove(aLi[index])
     }else {
      aLi[index].style.top=0;
     }
    
    }
   }
   //
   aBtn[index].className="current";
   aLi[index].style.zIndex=200;
   aLi[index].style.background=aClor[index][0];
   aDiv[index].style.background=aClor[index][1];
   autoPlay();
   //
   oTab.οnmοuseοver=function(){
    clearInterval(playTimer);
   }
   oList.οnmοuseοut=function(){
    autoPlay();
   }
   //
   function autoPlay(){
    playTimer=setInterval(function(){
     index==aBtn.length-1 && (bOrder=false);
     index==0 && (bOrder=true);
     bOrder ? index++ : index--;
     //console.log(index);
     aBtn[index].onclick();
    },5000)
   }
   //
   function showMove(obj){
    clearInterval(timer);
    timer=setInterval(function(){
     doMove(obj)
    },30)
   }
   //
   function doMove(obj){
    var iSpeed=obj.offsetTop/10;
    iSpeed=iSpeed>0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
    obj.offsetTop<=0 ? clearInterval(timer) : obj.style.top=obj.offsetTop-iSpeed+"px";
   }
  }
  </script>
 
  <!-- Site styles -->
  <link rel="stylesheet" type="text/css" href="lib/css/reset.css" />
 
  <style>
  body{background:#000;text-align:center;font:12px/20px Arial;}
  #tab-wrap {width:100%;position:relative;overflow:hidden;}
  #tab-wrap .list {position:relative;height:252px;}
  #tab-wrap .list li {position:absolute;top:0;left:0;width:100%;height:252px;}
  #tab-wrap .list li img {margin:0 auto;width:990px;}
  #tab-wrap .list li .bg-right {position:absolute;top:0;right:0;width:50%;height:252px;z-index:-1;}
  #tab-wrap .count {position:absolute;left:50%;width:10px;height:100px;top:100px;margin-left:470px;z-index:300;}
  #tab-wrap .count li {float:left;width:10px;height:10px;background:#ccc;margin-bottom:10px;}
  #tab-wrap .count li:hover{cursor:pointer;}
  #tab-wrap .count li.current {background:#85BE2E;}
  </style>
 </head>
 <body>
  <div id="tab-wrap">
   <ul class="list">
    <li>
     <img src=" http://js.alixixi.com/UploadPic/2012-11/20121119116640990.jpg" width="990" height="252" />
     <div class="bg-right"></div>
    </li>
    <li>
     <img src=" http://js.alixixi.com/UploadPic/2012-11/201211191164436085.jpg" width="990" height="252" />
     <div class="bg-right"></div>
    </li>
    <li>
     <img src=" http://js.alixixi.com/UploadPic/2012-11/201211191171259810.jpg" width="990" height="252" />
     <div class="bg-right"></div>
    </li>
    <li>
     <img src=" http://js.alixixi.com/UploadPic/2012-11/201211191172831190.jpg" width="990" height="252" />
     <div class="bg-right"></div>
    </li>
   </ul>
  </div>
 </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值