各位大神們,幫忙看看
window.onload=function(){
var Li1=document.getElementById('li1');
var Li2=document.getElementById('li2');
var Li1.timer=null;
var Li2.timer=null;
Li1.onmouseover=function(){
startMove(this,'height',400)
}
Li1.onmouseout=function(){
startMove(this,'height',100)
}
Li2.onmouseover=function(){
startMove(this,'width',400)
}
Li2.onmouseout=function(){
startMove(this,'width',200)
}
}
function getStyle(obj,attr)
{
if(obj.currentStyle){return obj.currentStyle[attr];}
else{return getComputedStyle(obj,false)[attr];}
}
function startMove(obj,attr,iTarget){
var icur=parseInt(getStyle(obj,attr));
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(iTarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==iTarget){clearInterval(obj.timer);}
else{obj.style[attr]= icur + speed +'px';}
},30);
}
第三行第四行定義初始化了兩個timer為啥就不能動了,還有緩沖效果怎么出不來,speed/8的時候效果不對,去掉除以8不能緩沖了,怎么回事呀
2016-08-18
timer不是變量,它只是節點的自定義屬性,直接就可以添加;而且聲明變量的方式是錯誤的,所以下面的代碼不會執行,建議多看控制臺信息。那個女老師講的課還是有很多問題的。