ITPub博客

首页 > 应用开发 > > 帮我看下,为什么我使用链式调用时,函数不会执行,为什么?

帮我看下,为什么我使用链式调用时,函数不会执行,为什么?

作者:古月雪 时间:2019-07-30 09:48:20 0 删除 编辑
function getComputer(obj,attr){
    if(obj.currentStyle){
        return obj.currentStyle[attr];
    }else{
        return getComputedStyle(obj,false)[attr];
    }
}
function startMove(obj,attr,target,fn) {
        clearInterval(obj.timer);
    obj.timer=setInterval(function(){
        if(attr=="opacity"){
            var cur=Math.round(parseFloat(getComputer(obj,attr))*100);
        }else{
            var cur=parseInt(getComputer(obj,attr));
        }

        var speed=target-cur;
        speed>0 ?(speed=Math.ceil(speed/3)):(speed=Math.floor(speed/3));
        if(cur==target){
            clearInterval(obj.timer);
            if(fn){
                fn();
            }
        }else{
            if(attr=="opacity"){
                // obj.style.filter=Alpha("opacity:'+(cur+speed)+");
                obj.style.opacity=(speed+cur)/100;
            }else{
                obj.style[attr]=cur+speed+"px";
            }

        }
    },300)
}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3711/viewspace-3132000/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-09

  • 博文量
    160
  • 访问量
    1175