不间断文字滚动
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>无标题文档</title>
- </head>
- <body>
- <div style="width:543px;height:46px;overflow:hidden; border:#000 1px solid;" onMouseOver="stop();" onMouseOut="start();">
- <table width="543" id="scrollimg" border="0" >
- <tr>
- <td id="simg"><table width="543" height="21" border="0">
- <tr> <td><a href="index.htm">不间断文字滚动</a></td> </tr>
- </table></td>
- <td id="simg1"></td>
- </tr>
- </table>
- <script LANGUAGE="JavaScript">
- var tm=null
- function newsScroll() {
- if(scrollimg.parentNode.scrollLeft!=546) //如果滚动的距离不是一整行的宽度就继续滚动
- scrollimg.parentNode.scrollLeft++;
- else
- scrollimg.parentNode.scrollLeft=0
- }
- window.onload=function() {
- simgsimg1.innerHTML=simg.innerHTML
- tm=setInterval('newsScroll()',20) //调节速度
- }
- function stop()
- {
- clearInterval(tm)
- }
- function start()
- {
- tm=setInterval('newsScroll()',20)
- }
- </script>
- </body>
- </html>
关键在于js的newsScroll()函数上,这个是说如果一整行没有滚动玩(width==width),那就滚动一个像素,否则就是说一行滚动完了,哪就把把scrollLeft置零,重新开始滚动。
setInterval是延时函数,后面的数字是多少毫秒后开始调用函数,改动它可以调节滚动的速度。