晕了晕了
window.onload = function(){ var box = document.getElementById('box1'); box.onmouseover = function(){ run(0); } box.onmouseout = function(){ run(-100); } } var timer = null; function run(tar){ clearInterval(timer); var box = document.getElementById('box1'); timer = setInterval(function(){ var speed = (tar - box.offsetLeft) / 20; speed = speed > 0 ? Math.ceil(speed):Math.floor(speed); if(box.offsetLeft == tar){ clearInterval(timer); } else { box.style.left = box.offsetLeft + speed +'px'; } },30); }
为什么会在left:133px处停下