JS怎么一直在抖動(dòng)
<!DOCTYPE?html> <html> <head> ????<meta?charset="utf-8"> ????<title>練習(xí)JS</title> </head> <style?type="text/css"> ????body{ ????????margin:0; ????????padding:0; ????} ????#div1{ ????????width:200px; ????????height:140px; ????????background-color:?red; ????????left:?-202px; ????????position:?relative; ????} ????#div1?span{ ????????width:20px; ????????height:?50px; ????????background:?#eee; ????????position:?absolute; ????????left:?200px; ????????top:75px; ????} </style> <body> <div?id="div1"> ????<span?id="share">分享</span> </div> <script> ????window.onload?=?function(){ ????????var?wsc?=?document.getElementById('div1'); ????????wsc.onmouseover?=?function(){ ????????????startMove(0); ????????} ????????wsc.onmouseout?=?function(){ ???????? starMove(-200); ????????} ????} ????var?timer?=?null; ????function?startMove(iTarget){ ???? clearInterval(timer); ????????var?wsc?=?document.getElementById('div1'); ????????timer?=?setInterval(function(){ ???????? var?speed?=?0; ???????? if(wsc.offsetLeft?>?iTarget){ ???????? speed?=?-10; ???????? } ???????? else{ ???????? speed=10; ???????? } ???????? if(wsc.offsetLeft?==?iTarget){ ???????? clearInterval(timer); ???????? } ????????else{ ????????????wsc.style.left?=?wsc.offsetLeft?+?speed?+'px'; ????????} ????????},30) ????} </script> </body> </html>
JS怎么一直在抖動(dòng),完全抄老師寫(xiě)的 ?可是還是一直在抖動(dòng)。。。到底哪里寫(xiě)錯(cuò)的?
2015-12-10
2016-03-28
應(yīng)該是移動(dòng)到span上div動(dòng)吧,你這個(gè)寫(xiě)的是移動(dòng)到div上div動(dòng),而且div都已經(jīng)-200,你怎么onmouseover的
2016-01-29
你的div的css??left:?-202px; 改成-200 試試 我試了下可以 你再試試
2015-12-10
兼容性問(wèn)題