有關(guān)oBox[i].timer=null;的 問題?
有關(guān)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>
2015-10-31
length那里應(yīng)該是
其次是下面的offsetLeft 應(yīng)該改成 offsetWidth
2015-10-05
?for(var i=0;i<=oBox.length;i++) ?這里取不到length,是<length
2015-09-09
for里面判斷條件的=去掉試下