无缝幻灯片2

上一篇写了一个无缝幻灯片。但是一个朋友说。我那个只适合做纯效果。如果在上面有一些操作,就会报错。

比如说:oul.getElementsByTagName(“li”)[0].这个时候没3秒钟返回的节点是一样的。在变化。针对这个需求,我就重新了一个。希望对大家有帮助。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <style>
           *{
              margin:0;
              padding:0;
           }
           div{
              width: 600px;
              height: 300px;
              overflow: hidden;
               position: relative;
                 margin:0 auto;
           }
           ul{
               position: absolute;
               left:0;
               top:0;
           }
           li{
              width: 600px;
              height: 300px;
              float: left; 
           }
           li.text{
               position: absolute;
               top:0;
           }
        </style>
    </head>
    <body>
        <div id="zd">
            <ul>
                <li style="background:#ff00ff" data-index="0"></li>
                <li style="background:#ff0010" data-index="1"></li>
                <li style="background:#0000ff" data-index="2"></li>
            </ul>
        </div>
        <script>
              var timer=null;
              function $(id){
                  return document.getElementById(id);
              }
               function getClass(obj,name){
                if(obj.currentStyle){
                    return obj.currentStyle[name]//IE
                }else{
                     return getComputedStyle(obj,false)[name]//IE
                }
            }
            function Stratmove(obj,json,funEnd,call){
               clearInterval(obj.timer);
               obj.timer=setInterval(function(){
                   for(var attr in json){
                       var bStop=true,
                           cuur=parseFloat(getClass(obj,attr)),
                           speed=0;
                       if(attr=="opacity"){
                          cuur=Math.round(parseFloat(getClass(obj,attr))*100);
                       }else{
                          cuur=parseFloat(getClass(obj,attr));
                       }
                       speed=(json[attr]-cuur)/8;
                       speed=speed>0?Math.ceil(speed):Math.floor(speed);
                       if(cuur!=json[attr]){
                            bStop=false;
                       }
                       if(attr=="opacity"){
                            obj.style["opacity"]=(cuur+speed)/100;
                            obj.style["filter"]="alpha(opacity="+cuur+speed+")";

                       }else{
                            obj.style[attr]=Math.round(cuur+speed)+"px";
                       }
                       if(bStop){
                          clearInterval(obj.timer);
                          if(call)call();
                       }
                       if(funEnd)funEnd();
                   }
               },30)
            }
              var oul=$("zd").getElementsByTagName("ul")[0],
                  oli=oul.getElementsByTagName("li"),
                  u=0,
                  oliW=oli[0].offsetWidth;
                  for (var i = 0; i < oli.length; i++) {
                      oli[i].className="text";
                      oli[i].style.left=oliW*i+"px";
                  };
            var timersd=setInterval(function(){
                   for (var i = 0; i < oli.length; i++) {
                           calls(i);
                           var oliL=oli[i].offsetLeft;
                           if(oliL%oliW==0){
                              Stratmove(oli[i],{"left":oliL-oliW},null);
                           } 
                      };
            },3000)
            function calls(z){
                   var oliL=oli[z].offsetLeft;
                      if(oli[z].offsetLeft==-oliW){
                       oli[z].style.left=oliW*(oli.length-1)+"px";
                  }

            }
        </script>
    </body>
</html>
演示地址: http://runjs.cn/detail/ivpslp2r

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值