首页 > 代码库 > 简单animate方法的封装

简单animate方法的封装


function animate(ele,json,fn){
clearInterval(ele.timer);
ele.timer = setInterval(function () {
var bool = true;
console.log(1);
for(var k in json){
if(k == "opacity"){
var leader = getStyle(ele,k)*100||0;
var step = (json[k]*100-leader)/10;
step = step>0?Math.ceil(step):Math.floor(step);

ele.style[k] = (leader+step)/100;
        //兼容IE678
ele.style.filter = "alpha(opacity = "+(leader+step)+")"
console.log(getStyle(ele, k));
if( getStyle(ele,k) != json[k] ){
bool = false;
}

}else if(k=="z-index"){
ele.style.zIndex=json[k];
}else{
var leader = parseInt(getStyle(ele,k))||0;
var step = (json[k]-leader)/10;
step = step>0?Math.ceil(step):Math.floor(step);

ele.style[k] = step+leader+"px";

if(parseInt(getStyle(ele,k))!=json[k]){
bool = false;
}
}
}
if(bool){
clearInterval(ele.timer);
if(fn){
fn();
}
}
},60)
}

简单animate方法的封装