//获取样式
function getStyle(obj,attr){
return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj,false)[attr];
}
//完美运动
function startMove(obj,json,fn){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var stop = true;
for(var attr in json){
var cur = 0;
//设置初值
if(attr == 'opacity'){
cur = parseInt(parseFloat(getStyle(obj,attr)) * 100);
}else{
cur = parseInt(getStyle(obj,attr));
}
//计算速度
var speed = (json[attr] - cur) / 10;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
//判断停止
if(cur != json[attr]){
stop = false;
}
if(attr == 'opacity'){
obj.style.filter ='alpha(opacity=' + (cur + speed) + ')';
obj.style.opacity = (cur + speed) / 100;
}else{
obj.style[attr] = (cur + speed) + 'px';
}
}
if(stop){
clearInterval(obj.timer);
if(fn){
fn();
}
}
},30);
}
function getStyle(obj,attr){
return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj,false)[attr];
}
//完美运动
function startMove(obj,json,fn){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var stop = true;
for(var attr in json){
var cur = 0;
//设置初值
if(attr == 'opacity'){
cur = parseInt(parseFloat(getStyle(obj,attr)) * 100);
}else{
cur = parseInt(getStyle(obj,attr));
}
//计算速度
var speed = (json[attr] - cur) / 10;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
//判断停止
if(cur != json[attr]){
stop = false;
}
if(attr == 'opacity'){
obj.style.filter ='alpha(opacity=' + (cur + speed) + ')';
obj.style.opacity = (cur + speed) / 100;
}else{
obj.style[attr] = (cur + speed) + 'px';
}
}
if(stop){
clearInterval(obj.timer);
if(fn){
fn();
}
}
},30);
}