function startMove(obj,json,endFn){
//假设
var flag = true;
//关闭定时器
clearInterval(obj.timer);
//打开定时器
obj.timer = setInterval(function(){
//for in 执行多组属性同时应用
for(var attr in json){
//透明度属性的判断,获取当前属性值
var icur = 0;
if(attr == 'opacity'){icur = Math.round(parseFloat(getStyle(obj,attr))*100);}//Math.round去尾数取整
else{icur = parseInt(getStyle(obj,attr));}
//获取速度 ,速度为缓冲速度
var speed = (json[attr]-icur)/8;
//向上取整,向下取整
speed = speed >0?Math.ceil(speed):Math.floor(speed);
//判断是否所有属性值都等于目标值,不等为false定时器就不会提前关闭
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';}
}
//判断是否所有属性值都等于目标值,等于为true定时器就关闭
if(flag){clearInterval(obj.timer);endFn&&endFn();}//回调函数
},30);
}
function getStyle(obj,attr){return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj)[attr];}
李晓健
相关分类