function getStyle(obj,attr) { if(obj.currentStyle) { return obj.currentStyle[attr]; } else { //return obj.getComputedStyle(obj,false).getPropertyValue([attr]); return document.defaultView.getComputedStyle(obj,false)[attr]; } } function startMove(obj, json,fn) { clearInterval(obj.timer); obj.timer=setInterval(function(){ for(var attr in json) { //1取当前值 var iCur=0; if(attr=='opacity') { iCur=parseInt(parseFloat(getStyle(obj,attr))*100); }else { iCur=parseInt(getStyle(obj,attr)); } //2算速度 var iSpeed=(json[attr]-iCur)/8; iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed); //3检测停止 if(iCur==json[attr]) { var flg=false; for(var attr in json) { if(attr=='opacity') { if(json[attr]==parseInt(parseFloat(getStyle(obj,attr))*100)) { flg=true; }else { flg=false; break; } }else { if(json[attr]==parseInt(getStyle(obj,attr))) { flg=true; }else { flg=false; break; } } } //当所有运动都全部完成时关闭定时器 if(flg) { clearInterval(obj.timer); } //是否链式运动 if(fn) { fn(); } }else { if(attr=='opacity') { obj.style.filter='alpha(opacity:'+(iCur+iSpeed)+')'; obj.style.opacity=(iCur+iSpeed)/100; }else { obj.style[attr]=iCur+iSpeed+"px"; } } } },30); }