The perfect motion frame is the improvement and efficiency of the original arbitrary value motion frame, which uses the JSON to encapsulate the attributes to improve efficiency:
Window.onload=function(){ varOdiv=document.getelementsbytagname (' div ') [0]; Odiv.onmouseover=function() {Move ( This, {width:200,height:200}); } } functionGetStyle (obj,attr) {if(obj.currentstyle) {returncurrentstyle (obj) [attr]; }Else{ returngetComputedStyle (obj,false) [attr]; } } functionMove (OBJ,JSON,FN) {Obj.timer=setinterval (function(){ for(varattrinchJSON) { varIcur=0; if(attr = = ' opacity ') {Icur=parseint (parsefloat (GetStyle (obj,attr)) *100); }Else{icur=parseint (GetStyle (obj,attr)); } varSpeed= (json[attr]-icur)/8; Speed=speed>0?Math.ceil (Speed): Math.floor (speed); if(Icur = =Json[attr]) {clearinterval (Obj.timer); FN&&fn (); }Else{obj.style[attr]=icur+speed+ ' px '; } } },30); }
JS's Perfect motion frame