为什么只执行第一个,后面的链式函数没执行

来源:7-1 JS动画案例

ry836478606

2016-04-10 12:18

5709d3e80001470005000334.jpg


5709d3e80001124f05000224.jpg



function startMove(obj,json,fn){//四个参数,作用的对象,对象的哪个属性,作用的值是多少,回调函数,没退出该函数再执行里面的函数。

        // var obj=document.getElementsByTagName('ul')[1];


        clearInterval(obj.timer);

        obj.timer=setInterval(function(){

            var flag=true;

            for(var attr in json){            

                var icur=0;

                if (attr=="opacity") {

                    icur=Math.round(parseFloat(getStyle(obj,attr))*100);

                }

                else{

                    icur=parseInt(getStyle(obj,attr));

                }


                var speed=(json[attr]-icur)/8;

                   speed=speed>0?Math.ceil(speed):Math.floor(speed); 


                if(icur!=json[attr]){

                    flag=false;

                

                    if(attr=="opacity"){

                       obj.style.filter="Alpha(opacity="+(icur+speed)+")";

                       obj.style.opacity=(icur+speed)/100;   

                    }

                    else{

                    obj.style[attr]=icur+speed+"px";

                    // console.log(obj.style[attr]);

                  }


                if(flag){

                    clearInterval(obj.timer);

                    // console.log("down");

                    if(fn){

                        fn();

                    }

                }

              }

            }

      },30)

}


  //获得非行内定义的样式,封装函数

function getStyle(obj,attr){

   if (obj.currentStyle){

       return obj.currentStyle[attr];//针对IE浏览器;

   }else{

       return getComputedStyle(obj,false)[attr];//针对大多数浏览器;

   }

}


写回答 关注

2回答

  • sunfloweryll
    2016-04-14 14:30:00

    呵呵,但是宝宝想要全套的源码,自己留着用,请问您方便分享嘛?

  • sunfloweryll
    2016-04-10 18:55:50

    求楼主分享一根move.js的源码给我,好吗?谢谢,思密达

    ry8364... 回复sunflo...

    需要用到的源码就这些

    2016-04-14 14:25:10

    共 3 条回复 >

JS动画效果

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

113923 学习 · 1443 问题

查看课程

相似问题