TextSlider = function(className) {
document.write("
");
this.item = [];
this.width = this.height = this.speed = this.pixel = this.interval =
this.size = this.moveCount = this.X = this.Y = 0;
this.direction = "";
this.pLayer = document.getElementById("TextSliderPLayer_"+ className);
this.layer = document.getElementById("TextSliderLayer_"+ className);
this.align = "left";
this.intervalId = null;
this.className = className;
this.isPause = false;
}
TextSlider.prototype.init = function() {
with (this.pLayer.style) {
width = this.width+"px";
height = this.height+"px";
overflow = "hidden";
}
with (this.layer.style) {
width = this.direction=='up' || this.direction=='down' ? this.width+"px" : this.size*(this.item.length+1)+"px";
height = this.direction=='up' || this.direction=='down' ? this.size*(this.item.length+1)+"px" : this.height+"px";
top = 0;
left = 0;
position = "relative";
}
if( this.direction=='up' || this.direction=='down' ) {
for (var i=0; i";
if (this.direction=='up' || this.direction=='down') {
__html += "";
for (var i in this.item)
__html += "| "+this.item[i]+" |
";
__html += "
";
}
else{
__html += "";
for (var i in this.item)
__html += "| "+this.item[i]+" | ";
__html += "
";
}
__html += "";
this.layer.innerHTML = __html;
this.start();
}
TextSlider.prototype.start = function() {
this.intervalId = setInterval(this.className+".move()", this.speed);
}
TextSlider.prototype.move = function() {
if (this.isPause) return;
switch (this.direction) {
case "up": this.Y -= this.pixel; break;
case "down": this.Y += this.pixel; break;
case "left": this.X -= this.pixel; break;
case "right": this.X += this.pixel; break;
}
if (this.direction=='up' || this.direction=='down') {
if (Math.abs(this.Y)%this.size==0) this.stop();
this.layer.style.top = this.Y;
}
else{
if (Math.abs(this.X)%this.size==0) this.stop();
this.layer.style.left = this.X;
}
}
TextSlider.prototype.stop = function() {
clearInterval(this.intervalId);
switch (this.direction) {
case "up":
if (Math.abs(this.Y) >= parseInt(this.layer.style.height,10)-this.size) this.Y = this.layer.style.top = 0;
break;
case "down":
if (Math.abs(this.Y) <= 0) this.Y = this.layer.style.top = -this.size*(this.item.length-1);
break;
case "left":
if (Math.abs(this.X) >= parseInt(this.layer.style.width,10)-this.size) this.X = this.layer.style.left = 0;
break;
case "right":
if (Math.abs(this.X) <= 0) this.X = this.layer.style.left = -this.size*(this.item.length-1);
break;
}
setTimeout(this.className+".start()", this.interval);
}
TextSlider.prototype.pause = function() {this.isPause = true;}
TextSlider.prototype.unpause = function() {this.isPause = false;}