缓冲代码在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上实验十多次一点问题都没有