window.onload=function(){ var oDiv=document.getElementById('div1'); oDiv.onmouseover=function(){ //startMove(10,0); startMove(0); } oDiv.onmouseout=function(){ //startMove(-10,-200); startMove(-200); }}//一個參數,兩個參數及無參數方法function startMove(iTarget){ clearInterval(timer); var oDiv=document.getElementById('div1'); var timer=null; var speed=0; timer=setInterval(function(){ if (oDiv.offsetLeft>iTarget) { speed=-10; }else{ speed=10; } if (oDiv.offsetLeft==iTarget) { clearInterval(timer); }else{ oDiv.style.left=oDiv.offsetLeft+speed+'px'; } },30);}
為什么移動到最后-10到0或是190-200的時候這個div就開始不停的抖動
jokec
2015-11-26 17:30:22