不懂為什么(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
當(dāng)(itarget-odiv.offsetLeft)/20=10/20=0.5PX時(shí),oDiv.style.left = oDiv.offsetLeft+speed+'px';=190+0.5=190.5px,像素出現(xiàn)了小數(shù)程序無法執(zhí)行下去。
2016-04-18
就是因?yàn)槟莻€(gè)offsetLeft屬性的值是不能帶小數(shù)的。所以要想辦法用Math的方法把speed變成整數(shù),這樣才能把offsetLeft弄成整數(shù).
2016-04-10
請(qǐng)檢查你的樣式表里面有沒有加border,offsetLift獲取的左值+邊框的值