speed定义那两条代码为什么不能写在计时器外面?我试过效果不一样,但我觉得表达意思一样啊?求大神解惑
function startMove(obj,iTarget){
var speed=(iTarget-obj.offsetWidth)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
clearInterval(obj.timer);
obj.timer=setInterval(function(){
//var speed=(iTarget-obj.offsetWidth)/10;
//speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==iTarget){
clearInterval(obj.timer);
}else{
obj.style.width=obj.offsetWidth+speed+"px"
}
},30);
}