哪位大牛能解釋一下26行中的fn()是什么意思?求指教?。?!
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];//針對IE瀏覽器
}else{
return getComputedStyle(obj,false)[attr];//針對火狐瀏覽器
}
}
function startMove(obj,attr,iTarget,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
//取當前的值
var icur=0;
if(attr=="opacity"){
? ?icur=Math.round(parseFloat(getStyle(obj,attr))*100);//parseFloat是取小數的函數,這塊注意如果不加Math,鼠標移上去不是1,移出來也不是0.3。
}else{
icur=parseInt(getStyle(obj,attr));
}
//算速度
var speed=(iTarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);//緩沖運動,一定要給速度取整。
//檢測停止
if(icur==iTarget){
clearInterval(obj.timer);
if(fn){
fn();
}
}else{
if(attr=="opacity"){
obj.style.filter="alpha(opacity:"+(icur+speed)+")";//針對IE瀏覽器
obj.style.opacity=(icur+speed)/100;//針對火狐,chorme瀏覽器
}else{
obj.style[attr]=icur+speed+"px";
}
}
},30)
}
2016-12-11
如果fn這個參數(在這里是函數)存在,則執行fn