oDiv.offsetLeft替換成oDiv.style.left 遇到bug
var?timer=null; function?stateMove(iTarget){ var?oDiv=document.getElementById('div1'); clearInterval(timer); if(oDiv.offsetLeft?>?iTarget){ speed=-10; }else{ speed=10 }; timer=setInterval(function(){ if(oDiv.offsetLeft==iTarget){ clearInterval(timer); }else{ oDiv.style.left=oDiv.offsetLeft+speed+'px'; }; },30); }
這段代碼為什么使用 if(oDiv.offsetLeft > iTarget){ ? ?而不是使用if(oDiv.style.left> iTarget){ ?和目標(biāo)比較 。
我試過了第二種方法 ?出現(xiàn)了一點(diǎn)小bug就是div在結(jié)束的時(shí)候 一直在跳動,這是為什么? ?
2017-01-04
style不能用來做判斷
2015-04-22
謝謝!
2015-04-22
http://www.cnblogs.com/woshilee/articles/1951457.html