不懂為什么(itarget-odiv.offsetLeft)/20 之后left就回不到200或者-200了。。。。
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';
}
2016-04-10
當(itarget-odiv.offsetLeft)/20=10/20=0.5PX時,oDiv.style.left = oDiv.offsetLeft+speed+'px';=190+0.5=190.5px,像素出現了小數程序無法執行下去。
2016-04-18
就是因為那個offsetLeft屬性的值是不能帶小數的。所以要想辦法用Math的方法把speed變成整數,這樣才能把offsetLeft弄成整數.
2016-04-10
請檢查你的樣式表里面有沒有加border,offsetLift獲取的左值+邊框的值