为什么这段代码有Bug
function MoveModelFn(obj,json,fn){ //var flag=true; clearInterval(obj.timer); obj.timer=setInterval(function(){ 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)/10; var 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)+')';//icur原始值+变化值speed obj.style.opacity=(icur+speed)/100; }else{ obj.style[attr]=icur+speed+"px"; } }else { clearInterval(obj.timer); // 回调函数 if (fn) { fn(); } } } },30)
如果不设立标杆。用if()else 有有bug