function startMove(obj,json,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var flag=true;
//遍历json
for(var attr in json)
{
//1、取当前值
var m=0;
if(attr=="opacity"){
m=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{m=parseInt(getStyle(obj,attr));}
//2、算速度
var speed=(json[attr]-m)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//3、检测停止
if(m!=json[attr]){
flag=false;
if(attr=="opacity"){
obj.style.filter="alpha(opacity:"+m+speed+")";
obj.style.opacity=(m+speed)/100;
}
else{obj.style[attr]=m+speed+"px";}
} }
if(flag){
clearInterval(obj.timer);
if(fn){fn();}
}
},30)
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{return getComputedStyle(obj,false)[attr];}
}
添加回答
举报
0/150
提交
取消