window.onload=function(){
var aLi=document.getElementsByTagName('li');
for(var i=0;i<aLi.length;i++){
aLi[i].timer=null;
aLi[i].onmouseover=function(){
startMove(this,400);
}
aLi[i].onmouseout=function(){
startMove(this,200);
}
}
}
function getStyle(obj,attr)
{
if(obj.currentStyle){return obj.currentStyle[attr];}//IE
else{return getComputedStyle(obj,false)[attr];}//firefox
}
function startMove(obj,iTarget){
var icur=parseInt(getStyle(obj,'height'))
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(iTarget-icur);
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==iTarget){clearInterval(obj.timer);}
else{obj.style.height= icur + speed +'px';}
},30);
}
怎么啦,哪里出错了啊,感觉用style就不出效果,offset可以
aLi[i].timer=null;首先说一下,timer是节点自定义属性,不需要初始化为null;你应该去看看width、clientWidth、offsetWidth的定义。