
oBtn4.onclick=function(){
boxrun( oDiv3,'width',400,20,function(){
alert('aaa')
})
}
function boxrun(obj,attr,target,speed,callback){
clearInterval(obj.timrA)
var nowValue=parseInt(getComputedStyle(obj,null)[attr])
if( nowValue>target){
speed=-speed
}
obj.timrA=setInterval(function(){
var oldValue=parseInt(getComputedStyle(obj,null)[attr])
var newValue=oldValue+speed
if( (speed<0&&newValue<target)||(speed>0&&newValue>target)){
newValue=target
}
obj.style[attr]=newValue+"px"
if(newValue==target){
clearInterval(obj.timrA)
callback()&&callback
}
},30)
}
为什么newValue没到达target值时执行了alert()