var TextRoll = function(block, con1, con2, speed){
function $(id){
return document.getElementById(id);
}
this.moveBlock = $(block);
this.content1 = $(con1);
this.content2 = $(con2);
this.content2.innerHTML = this.content1.innerHTML;
this.speed = !isNaN(speed) ? speed : 20;
var textRoll = this;
var speed = this.speed;
var timer = setInterval(function(){textRoll.marquee();}, this.speed);
this.moveBlock.onmouseover = function(){
clearInterval(timer);
}
this.moveBlock.onmouseout = function(){
timer = setInterval(function(){textRoll.marquee();}, speed);
}
}
TextRoll.prototype.marquee = function(){
if(this.content2.offsetWidth - this.moveBlock.scrollLeft <= 0){
this.moveBlock.scrollLeft -= this.content1.offsetWidth;
}else{
this.moveBlock.scrollLeft ++;
}
}
new TextRoll('move_block', 'content1', 'content2');
|