function?getStyle(elem,attr){ ????var?result?=?null; ????result?=?elem.currentStyle?elem.currentStyle[attr]:getComputedStyle(elem,false)[attr]; ????if(attr=="opacity"){ ????????return?parseInt(parseFloat(result)*100); ????} ????return?parseInt(result); } var?timer?=?null; //多個屬性同時變化 function?startMove(elem,json,fn){ ????var?isStop?=?true;????????????//所有值都到達(dá) ????clearInterval(elem.timer); ????elem.timer?=?setInterval(function(){ ????????//歷遍json屬性 ????????for(var?attr?in?json){ ????????????//1.取當(dāng)前與速度 ????????????var?offset??=?json[attr]; ????????????var?curAttr?=?getStyle(elem,attr); ????????????var?speed???=?(offset?-?curAttr)/8; ????????????speed?=?speed?>?0??Math.ceil(speed):Math.floor(speed); ???????????? ????????????//2.檢測停止 ????????????if(offset!=curAttr){ ????????????????isStop?=?false; ????????????} ????????????if(attr=="opacity"){ ????????????????elem.style.filter?=?"alpha(opacity:"+(curAttr+speed)+")"; ????????????????elem.style.opacity=?(curAttr+speed)/100; ????????????}else{ ????????????????elem.style[attr]?=?curAttr?+?speed?+?"px"; ????????????} ????????} ????????//所有值都到達(dá)目標(biāo)值,則停止 ????????if(isStop){ ????????????clearInterval(elem.timer); ????????????if(fn){?fn();?} ????????} ????},30); }

gzw19931217
2014-10-25
0 回答
舉報
0/150
提交
取消