标签:tin anim 封装 style timer 简单 for als ceil
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)
}
标签:tin anim 封装 style timer 简单 for als ceil
原文地址:http://www.cnblogs.com/summer0319/p/6052590.html