无间断上下滚动

<!--CTYPE HTML PUBLIC "-//w3c//dtd html 4.0//e--><script language="javascript">

    /*
  *    @function:
  *   @author:hanpoyangtitan
  *   @param: width,height,speed,panel,directin,item
  *   @date:2007-5-21
  */

    function Marquee(width,height,delay,panel,direction)
 {
     this._w=width;         //外层容器宽度
  this._h=height;        //外层容器高度
  this._delay=delay;        //滚动的速度
  this.panel=panel;
  this.container=null;
  this.scrollBox_1=null;
  this.scrollBox_2=null; 
  this._d=direction;     //方向
  this._arr=[];        //滚动的内容
 }

 Marquee.prototype.push=function(str)
 {
     this._arr.push(str);
 }

 Marquee.prototype.toString=function(_arr)
 {
      var html="";
      switch(this._d)
   {
    case "up":
    case "down":
        for(var i=0;i<_arr.length;i++)
        {
            html+="<div style=/"vertical-align:middle;/"><a href=/""+_arr[i].link+"/" title=/""+_arr[i].title+"/" target=/""+_arr[i].target+"/">"+_arr[i].text+"</a></div>";
        }
    break;
   }
   return html;
 }

 Marquee.prototype.init=function()
 {
     var itemstring=this.toString(this._arr);
     this.container=document.createElement("DIV");
  this.panel.appendChild(this.container);
     this.container.style.width=this._w;
  this.container.style.height=this._h;

  //设置scrollBox_1的属性
  this.scrollBox_1=document.createElement("DIV");

  

  //设置scrollBox_2的属性
  this.scrollBox_2=document.createElement("DIV");
 
  

  this.scrollBox_1.innerHTML=itemstring;
  this.scrollBox_2.innerHTML=itemstring;
  this.container.appendChild(this.scrollBox_1);
  this.container.appendChild(this.scrollBox_2);

     if(this._d=="up" || this._d=="down")
  {
      this.container.style.overflowY="hidden";
      this.scrollBox_1.style.width=this._w;
   this.scrollBox_2.style.width=this._w;
      if(this._d=="down")
   {
       this.container.scrollTop=this.container.scrollHeight;
   }
  }
  this.scroll();
 
 }

 Marquee.prototype.scroll=function()
 {
  switch(this._d)
  {
   case "up":
       if(this.container.scrollTop-this.scrollBox_1.offsetHeight>=0)
    {
        this.container.scrollTop-=this.scrollBox_1.offsetHeight;
    }
    this.container.scrollTop++;
   break;
   case "down":
       if(this.container.scrollTop-this.scrollBox_1.offsetHeight<=(0-this.container.offsetHeight))
    {
        this.container.scrollTop+=this.scrollBox_1.offsetHeight;
    }
    this.container.scrollTop--;
   break;
   default:
  }
  var obj=this;
  setTimeout(function(){obj.scroll()},this._delay);
 }


 function nodeElement(link,text,title,target,className)
 {
      this.link=link;
   this.text=text;
   this.title=title;
   this.target=target;
   this.className=className;
 }

 window.οnlοad=function()
 {
     var m=new Marquee(200,25,100,document.getElementById("cc"),"up");
  m.push(new nodeElement("http://www.baidu.com","百度搜索引擎","百度一下,你就知道","_blank",""));
  m.push(new nodeElement("http://www.163.com","网易","中国网易","_blank",""));
  m.push(new nodeElement("http://www.yahoo.com","雅虎,门户","雅虎,门户","_blank",""));
  m.push(new nodeElement("http://www.csdn.net","中国程序员论坛","中国最大的程序员论坛,高手云集","_blank",""));
  m.init();
 }


 /*
     问题总结:当向下滚动时scrollTop=scrollHeight-container.offsetHeight
 */
 function debug(str)
 {
     document.body.insertAdjacentHTML("BeforeEnd",str);
 }
</script><style type="text/css">


  body{
       font-size:9pt;
   }</style>
<div id="cc" style="BORDER-RIGHT: #eeeeee 1px solid; BORDER-TOP: #eeeeee 1px solid; BORDER-LEFT: #eeeeee 1px solid; WIDTH: 200px; BORDER-BOTTOM: #eeeeee 1px solid; HEIGHT: 25px"></div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值