有关oBox[i].timer=null;的 问题?
有关oBox[i].timer=null;的 问题?
<script>
window.onload=function(){
<!-- var timer;-->
var oBox=document.getElementsByTagName("div");
for(var i=0;i<=oBox.length;i++){
oBox[i].timer=null;
oBox[i].onmouseover=function(){startMove(this,300);};
oBox[i].onmouseout=function(){startMove(this,0);};
}
function startMove(obj,target){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(target-obj.offsetLeft)/10;
speed=speed>0 ? Math.ceil(speed):Math.floor(speed);
if (obj.offsetLeft==target){
clearInterval(obj.timer);}
else{
obj.style.left=obj.offsetLeft+speed+"px";}
},30);
};
};
</script>