无聊时用动态原型改写的一个不间断向上滚动

 
  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. <script>
  7. <!--
  8. var i=0;
  9. function $(ID)
  10. {
  11.     var obj=document.getElementById(ID);
  12.     return obj;
  13. }
  14. function moveup(id,heigth)
  15. {
  16.     this.id=id;
  17.     $(this.id+2).innerHTML=$(this.id+1).innerHTML
  18.     if(typeof(moveup._initialized=="undefined"))
  19.     {
  20.         moveup.prototype.move=function()
  21.         {
  22.             if($(this.id+2).offsetHeight-$(this.id).scrollTop<=0) 
  23.             {
  24.                 $(this.id).scrollTop-=$(this.id+1).offsetHeight;
  25.             }
  26.             else{ 
  27.                 $(this.id).scrollTop++;
  28.             } 
  29.         }
  30.         moveup._initialized=true;
  31.     }
  32. }
  33. -->
  34. </script>
  35. <style>
  36. .demo{
  37. width:400px;
  38. height:20px;
  39. background:#FF0000;
  40. OVERFLOW: hidden;
  41. padding:0px;
  42. margin:0px;
  43. }
  44. .demo1{
  45. width:400px;
  46. padding:0px;
  47. margin:0px;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="demo" class="demo">
  53.   <div id="demo1" class="demo1"> 
  54.     1<br />
  55.     2<br />
  56.     3<br />
  57.     4<br />
  58.     5<br />
  59.   </div>
  60.   <div id="demo2"></div>
  61. </div>
  62. <script>
  63. var rollspeed=100;
  64. var obj=new moveup("demo",25);
  65. var t=setInterval("obj.move()",rollspeed);
  66. $("demo").onmouseover=function() {clearInterval(t)}//鼠标移上时清除定时器达到滚动停止的目的
  67. $("demo").onmouseout=function() {t=setInterval("obj.move()",rollspeed)}//鼠标移开时重设定时器
  68. </script>
  69. </body>
  70. </html>

以上代码只要把

 if($(this.id+2).offsetHeight-$(this.id).scrollTop<=0) 

            {

                $(this.id).scrollTop-=$(this.id+1).offsetHeight;

            }

            else{ 

                $(this.id).scrollTop++;

            } 

里的scrollTop改为scrollLeft

offsetHeight改为offsetWidth就可以改为向左或向右滚动了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一把编程的菜刀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值