js 通知

博客提供了一个使用JavaScript实现滚动信息效果的代码示例,包含JavaScript、CSS和HTML代码。通过设置滚动速度、容器和内容对象,实现信息在屏幕上滚动显示,还可通过鼠标悬停暂停滚动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自 : https://huhanlin-2008-163-com.iteye.com/blog/772506

  1. <script type="text/javascript" language="Javascript">  
  2. var scrlSpeed=1  
  3. // decreasing speed for mozilla  
  4. scrlSpeed=(document.all)? scrlSpeed : Math.max(1, scrlSpeed-1)  
  5. function initScroll(container,object){  
  6.     if (document.getElementById(container) != null){  
  7.         var contObj=document.getElementById(container);  
  8.         var obj=document.getElementById(object);  
  9.         contObj.style.visibility = "visible";  
  10.         contObj.scrlSpeed = scrlSpeed;  
  11.         widthContainer = contObj.offsetWidth;  
  12.         obj.style.left=parseInt(widthContainer)+"px";  
  13.         widthObject=obj.offsetWidth;  
  14.         interval=setInterval("objScroll('"+ container +"','"+ object +"',"+ widthContainer +")",20);  
  15.         contObj.onmouseover = function(){  
  16.             contObj.scrlSpeed=0;  
  17.         }  
  18.         contObj.onmouseout = function(){  
  19.             contObj.scrlSpeed=scrlSpeed;  
  20.         }   
  21.     }  
  22. }  
  23.   
  24. function objScroll(container,object,widthContainer){  
  25.     var contObj=document.getElementById(container);  
  26.     var obj=document.getElementById(object);  
  27.     widthObject=obj.offsetWidth;  
  28.     if (parseInt(obj.style.left)>(widthObject*(-1))){  
  29.         obj.style.left=parseInt(obj.style.left)-contObj.scrlSpeed+"px";  
  30.     } else {  
  31.         obj.style.left=parseInt(widthContainer)+"px";  
  32.     }  
  33. }  
  34.   
  35.    
  36.   
  37. // on page load we initiate scrolling  
  38. window.onload=function(){   
  39.     initScroll("scrlContainer", "scrlContent");  
  40. }  
  41.   
  42. </script>  



2.css 

Java代码 

 收藏代码

  1. <style type="text/css">  
  2. body{  
  3.     margin:0;  
  4.     padding:0;  
  5.     background:#fff;  
  6.     font: 70% Arial, Helvetica, sans-serif;  
  7. }  
  8. #scrlContainer{  
  9.     visibility:hidden;  
  10.     background:#f1f1f1;  
  11.     position:relative;  
  12.     overflow:hidden;  
  13.     width:250px;  
  14.     height:20px;  
  15.     line-height:20px;  
  16.     margin:1em;  
  17. }  
  18.   
  19. #scrlContent{  
  20.     position:absolute;  
  21.     left:0;  
  22.     top:0;  
  23.     white-space:nowrap;  
  24. }  
  25. </style>  



3.html 

Java代码 

 收藏代码

  1. <html>   
  2. <body>  
  3. <div id="scrlContainer">  
  4.     <div id="scrlContent">Some very, very useful information will  
  5. appear here, yet it will move around your screen so it will be hard to  
  6. read it. But the client wants it, so here it is. </div>  
  7. </div>                
  8. </body>  
  9. </html>   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值