function?startMove(obj,json,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var?flag=true;
//遍歷json
for(var?attr?in?json)
{
//1、取當(dāng)前值
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];}
}
麻煩看下我的JS移動(dòng)動(dòng)畫效果的封裝對(duì)不對(duì)
細(xì)嗅薔薇1
2016-03-30 18:17:40