move组件
function getStyle(obj,name){
return (obj.currentStyle || getComputedStyle(obj,false))[name];
}
function move(obj,json,options){
options=options || {};
options.duration=options.duration || 500;
options.easing=options.easing || 'linear';
var count=Math.floor(options.duration/30);
var start={};
var dis={};
for(var name in json){
start[name]=parseFloat(getStyle(obj,name));
if(isNaN(start[name])){
switch (name){
case 'left':
start[name]=obj.offsetLeft;
break;
case 'top':
start[name]=obj.offsetTop;
break;
case 'width':
start[name]=obj.offsetWidth;
break;
case 'height':
start[name]=obj.offsetHeight;
break;
case 'opacity':
start[name]=1;
break;
case 'padding-left':
start[name]=0;
break;
//font-size,border-width,margin-left....
}
}
dis[name]=json[name]-start[name];
}
var n=0;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
n++;
for(var name in json){
switch (options.easing){
case 'linear':
var scale=n/count;
var cur=start[name]+dis[name]*scale;
break;
case 'ease-in':
var scale=n/count;
var cur=start[name]+dis[name]*Math.pow(scale,3);
break;
case 'ease-out':
var scale=1-n/count;
var cur=start[name]+dis[name]*(1-Math.pow(scale,3));
break;
}
if(name=='opacity'){
obj.style[name]=cur;
obj.style.filter='alpha(opacity:'+cur*100+')';
}else{
obj.style[name]=cur+'px';
}
}
if(n==count){
clearInterval(obj.timer);
options.complete && options.complete();
}
},30);
}