﻿// JScript 文件

function Marquee(obj){
    this.obj=obj;
    var c=this;
    this.width=0;
    this.pWidth=0;
    this.left=0;
    this.add=1;
    this.timeout=50;
    this.interval=null;
    document.body.onload=function(){c.load();};
}

Marquee.prototype.load=function(){
    this.pWidth=this.obj.parentNode.offsetWidth;
    this.width=this.obj.offsetWidth;
    if(this.width<=this.pWidth)
        return;
    var c=this;
    var table=document.createElement('table');
    table.setAttribute('cellpadding','0')
    table.setAttribute('cellspacing','0')
    table.setAttribute('border','0')
    var tr=table.insertRow();
    var td_1=tr.insertCell();
    var td_2=tr.insertCell();
    var pNode=this.obj.parentNode;
    td_1.innerHTML=pNode.innerHTML;
    td_2.innerHTML=pNode.innerHTML;
    pNode.innerHTML='';
    pNode.appendChild(table);
    this.obj=table;
    table.onmouseover=function(){c.stop();};
    table.onmouseout=function(){c.start();};
    this.width=this.obj.offsetWidth;
  
    this.interval=setInterval(function(){c.move();},this.timeout);
}

Marquee.prototype.stop=function(){
    clearInterval(this.interval);
}

Marquee.prototype.start=function(){
    var c=this;
    this.interval=setInterval(function(){c.move();},this.timeout);
}

Marquee.prototype.move=function(){
    this.left=this.left-this.add;
    if(this.left<=(this.pWidth-this.width)){
            this.left=this.pWidth-this.width/2-this.add;
    }
    if(this.left<(-this.width)){
        this.left=this.pWidth;
    }
    this.obj.style.marginLeft=this.left+'px';
}


/*
有什么问题请到<a href='/bbs/forums.php?fid=21'>论坛</a>中发表<br>
<!-- http://www.webjx.com/ -->
<!-- bbs http://www.webjx.com/bbs-->

<!-- 把下列代码加到<body>区域内 -->
<base href="http://www.webjx.com">
<div id=demo style=overflow:hidden;height:33;width:200;background:#214984;color:#ffffff>
<table align=left cellpadding=0 cellspace=0 border=0>
<tr>
<td id=demo1 valign=top><img src="/img/link.gif"><img src="/img/link1.gif"><img src="/img/link2.gif"><img src="/img/link3.gif">
</td>
<td id=demo2 valign=top></td>
</tr>
</table>
</div>

<script>
var speed=30
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo2.offsetWidth-demo.scrollLeft<=0)
demo.scrollLeft-=demo1.offsetWidth
else{
demo.scrollLeft++
}
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>
*/
