緩沖代碼在firefox上運行正常,但在360瀏覽器中有時候會無限左移和右移?
<!DOCTYPE?html> <html> <head> <meta?charset="UTF-8"> <title>Document</title> <style> *{ margin:0; padding:?0; } ?????#div1{ ??????background:red; ??????width:?200px; ??????height:200px; ??????left:-200px; ??????position:?relative; ?????} ?????#share{ ????????position:?absolute; ????????display:?block; ????????left:200px; ????????width:50px; ????????height:75px; ????????top:20px; ????????background:?green; ?????} </style> <script> window.onload?=?function(){ var?oDiv?=document.getElementById('div1'); oDiv.onmousemove?=?function(){ startMove(0); } oDiv.onmouseout?=?function(){ startMove(-200); } var?timer?=?null; function?startMove(iTarget){ clearInterval(timer); var?oDiv?=document.getElementById('div1'); var?speed?=?(iTarget-oDiv.offsetLeft)/5; speed?=?speed>0?Math.ceil(speed):Math.floor(speed); timer?=?setInterval(function(){ if(oDiv.offsetLeft?==iTarget){ clearInterval(timer); }else{ oDiv.style.left?=?oDiv.offsetLeft+speed+"px"; } },30) } } </script> </head> <body> <div?id="div1"> <span?id?="share">分享</span> </div> </body> </html>
在360上實驗5次總會有一次會無限漂移,firefox上實驗十多次一點問題都沒有
2016-04-04
speed的定義這段代碼要放到定時器內(nèi)部函數(shù)里去
2016-03-26
firefox上也重現(xiàn)了Orz