不明白错在哪。。。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> body{margin: 0;padding: 0;} #div1{width:560px;height:660px;background-color:#0C4E7C;position:fixed;left:-560px;} span{width:20px;height:50px;background-color:#FFA500;position:absolute;left:560px;} </style> <script type="text/javascript"> window.onload=function(){ var div=document.getElementById("div1"); //var stl=window.getComputedStyle(div,null); //div.style.top=(document.documentElement.clientHeight/2)-parseInt(stl.height)/2+"px"; div.onmouseover=function(){ starMove(); } div.onmouseout=function(){ starMove1(); } } var timer=null; function starMove(){ clearInterval(timer); var div=document.getElementById("div1"); timer=setInterval(function(){ if(div.offsetLeft==0){ clearInterval(timer); } else{ div.style.left=div.offsetLeft+10+"px"; } },26) } function starMove1(){ clearInterval(timer); var div=document.getElementById("div1"); timer-setInterval(function(){ if(div.offsetLeft==-560){ clearInterval(timer); } else{ div.style.left=div.offsetLeft-10+"px"; } },26) } </script> </head> <body> <div id="div1"> <span>分享</span> </div> </body> </html>
我也是无了语。