有没有人跟我一样,火狐浏览器运行正确,谷歌浏览器并不能完全达到-200,还留有一小段?
<script type="text/javascript">
window.onload = function () {
var odiv = document.getElementById('div1');
odiv.onmouseover = function () {
startMove(0);
}
odiv.onmouseout = function () {
startMove(-200);
}
}
var timer = null;
function startMove (iTarget) {
clearInterval(timer);
var odiv = document.getElementById('div1');
timer = setInterval(function () {
var speed = (iTarget - odiv.offsetLeft)/20;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(odiv.offsetLeft == iTarget){
clearInterval(timer);
}else{
odiv.style.left = odiv.offsetLeft + speed + 'px';
}
},30);
}
</script>