function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ return getComputedStyle(obj,false)[attr]; } } function move(obj,json,num,fn){ var timer=null,attr=null;iCur=null,iTarget=null,iSpeed=null; clearInterval(obj.timer); obj.timer=setInterval(function(){ var onOff=true; for(attr in json){ iTarget=json[attr]; iTarget=parseInt(iTarget); if(attr=="opacity"){ iCur=parseInt(parseFloat(getStyle(obj,attr)*100)); if(isNaN(iCur)){ iCur=100; } }else{ iCur=parseInt(getStyle(obj,attr)); } if(iCur<iTarget){ iSpeed=Math.ceil((iTarget-iCur)/num); }else{ iSpeed=Math.floor((iTarget-iCur)/num); } if(iCur!=iTarget){ onOff=false; if(attr=="opacity"){ obj.style[attr]=(iCur+iSpeed)/100; obj.style.filter="alpha(opacity=iCur+iSpeed)"; }else{ obj.style[attr]=iCur+iSpeed+"px"; if(Math.abs(iSpeed)>Math.abs(iTarget-iCur)){ obj.style[attr]=iTarget+"px"; } } } } if(onOff){ clearInterval(obj.timer); fn&&fn.call(obj); } },30); }
您可能感兴趣的文章: