JS滚动代码出现问题,请教大家
代码如下所示,问题是第二轮滚动到第三行时,第三行显示了两次。程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>上滚</title> </head> <body> <div id="gg" style=" width:1000px; height:30px;"> <table width="1000" border="0" cellpadding="0" cellspacing="0" id="ggtab"> <tr> <td height="30" bgcolor="#CCCCCC">1111</td> </tr> <tr> <td height="30" bgcolor="#F2F2F2">2222</td> </tr> <tr> <td height="30" bgcolor="#CCCCCC">3333</td> </tr> </table> </div> <script type="text/javascript"> var o = document.getElementById("gg"); var tabo = document.getElementById("ggtab"); var marqueesHeight = 30; var stopscroll=false; with(o){ style.width=1000; style.height=marqueesHeight; style.overflow="hidden"; noWrap=true; onmouseover=new Function("stopscroll=true"); onmouseout=new Function("stopscroll=false"); } preTop=0; currentTop=marqueesHeight; stoptime=0; o.innerHTML+=o.innerHTML; function init_srolltext(){ o.scrollTop=0; setInterval("scrollUp2()",1); } function scrollUp2(){ if(stopscroll==true) return; currentTop+=5; if(currentTop>marqueesHeight+1) { stoptime+=1; currentTop=marqueesHeight; if(stoptime==100) { currentTop=0; stoptime=0; } } else { preTop=o.scrollTop; o.scrollTop+=5; if(preTop>=o.scrollTop){ o.scrollTop=marqueesHeight; o.scrollTop+=5; } } } init_srolltext(); </script> </body> </html>