为什么在滑出时会来回的晃动
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{margin:0;padding:0;} #div1{width:100px; height:300px; background:#98fb98; left:-100px; position:relative; } span{width:30px;height:100px;left:100px;background: #0000ff;position:absolute;} </style> <script type="text/javascript"> window.onload=function(){ var timer var odiv=document.getElementById('div1'); odiv.onmouseover=function(){ startmove(10,0); } odiv.onmouseout=function(){ startmove(-10,-100); } } function startmove(speen,itarget){ var odiv=document.getElementById('div1'); clearInterval(timer); var timer=setInterval(function(){ if(odiv.offsetLeft==itarget){ clearInterval(timer); } else{ odiv.style.left=odiv.offsetLeft+speen+'px'; } }, 100) } </script> </head> <body> <div id="div1"><span>分享</span></div> </body> </html>
不断的加10减10 一直晃动停不下来