完美运动框架
1 function getStyle(obj,attr) 2 { 3 if(obj.currentStyle) 4 { 5 return obj.currentStyle[attr]; 6 } 7 else 8 { 9 return getComputedStyle(obj,false)[attr]; 10 } 11 } 12 13 function move(obj,json,fn) 14 { 15 clearInterval(obj.timer); 16 obj.timer=setInterval(function(){ 17 var dd=true; 18 for(var attr in json) 19 { 20 var current=0; 21 if(attr=='opacity') 22 { 23 current=parseInt(parseFloat(getStyle(obj,attr))*100); 24 } 25 else 26 { 27 current=parseInt(getStyle(obj,attr)); 28 } 29 30 31 speed=(json[attr]-current)/8; 32 speed=speed>0?Math.ceil(speed):Math.floor(speed); 33 34 if(current!=json[attr]) 35 { 36 dd=false; 37 } 38 39 40 41 if(attr=='opacity') 42 { 43 obj.style.filter='alpha(opacity:'+(current+speed)+')'; 44 obj.style.opacity=(current+speed)/100; 45 } 46 else 47 { 48 obj.style[attr]=current+speed+'px'; 49 } 50 51 } 52 53 if(dd) 54 { 55 clearInterval(obj.timer); 56 if(fn) 57 { 58 fn(); 59 } 60 61 } 62 },30); 63 }