js不间断文字滚动

不间断文字滚动

Code:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. <title>无标题文档</title>  
  6. </head>  
  7.   
  8. <body>  
  9. <div style="width:543px;height:46px;overflow:hidden; border:#000 1px solid;" onMouseOver="stop();" onMouseOut="start();">       
  10.   <table   width="543"    id="scrollimg" border="0" >     
  11.   <tr>       
  12.   <td id="simg"><table width="543" height="21" border="0">
  13.                     <tr> <td><a href="index.htm">不间断文字滚动</a></td> </tr>          
  14.                  </table></td>     
  15.   <td id="simg1"></td>     
  16.   </tr>     
  17.   </table>    
  18.   <script   LANGUAGE="JavaScript">     
  19.   var   tm=null     
  20.   function   newsScroll()   {     
  21.   if(scrollimg.parentNode.scrollLeft!=546) //如果滚动的距离不是一整行的宽度就继续滚动   
  22.   scrollimg.parentNode.scrollLeft++;     
  23.   else     
  24.   scrollimg.parentNode.scrollLeft=0     
  25.   }     
  26.   window.onload=function()   {     
  27.   simgsimg1.innerHTML=simg.innerHTML     
  28.   tm=setInterval('newsScroll()',20)  //调节速度    
  29.   }     
  30.   function   stop()     
  31.   {     
  32.   clearInterval(tm)     
  33.   }     
  34.       
  35.   function   start()     
  36.   {     
  37.   tm=setInterval('newsScroll()',20)       
  38.   }     
  39.   </script>   
  40. </body>  
  41. </html>  

 关键在于js的newsScroll()函数上,这个是说如果一整行没有滚动玩(width==width),那就滚动一个像素,否则就是说一行滚动完了,哪就把把scrollLeft置零,重新开始滚动。

setInterval是延时函数,后面的数字是多少毫秒后开始调用函数,改动它可以调节滚动的速度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值