function scrolltext(content, btnprevious, btnnext, autostart) { this.delay = 10; this.lineheight = 20; this.amount = 1; //ע��:lineheightһ��ҫ������amount. this.direction = "up"; this.timeout = 1500; this.scrollcontent = this.$(content); this.scrollcontent.innerhtml += this.scrollcontent.innerhtml; //this.scrollcontent.scrolltop = 0; if (btnnext) { this.nextbutton = this.$(btnnext); this.nextbutton.onclick = this.getfunction(this, "next"); this.nextbutton.onmouseover = this.getfunction(this, "stop"); this.nextbutton.onmouseout = this.getfunction(this, "start"); } if (btnprevious) { this.previousbutton = this.$(btnprevious); this.previousbutton.onclick = this.getfunction(this, "previous"); this.previousbutton.onmouseover = this.getfunction(this, "stop"); this.previousbutton.onmouseout = this.getfunction(this, "start"); } this.scrollcontent.onmouseover = this.getfunction(this, "stop"); this.scrollcontent.onmouseout = this.getfunction(this, "start"); if (autostart) { this.start(); } } scrolltext.prototype.$ = function(element) { return document.getelementbyid(element); } scrolltext.prototype.previous = function() { cleartimeout(this.autoscrolltimer); cleartimeout(this.scrolltimer); this.scroll("up"); } scrolltext.prototype.next = function() { cleartimeout(this.autoscrolltimer); cleartimeout(this.scrolltimer); this.scroll("down"); } scrolltext.prototype.start = function() { cleartimeout(this.autoscrolltimer); this.autoscrolltimer = settimeout(this.getfunction(this, "autoscroll"), this.timeout); } scrolltext.prototype.stop = function() { cleartimeout(this.scrolltimer); cleartimeout(this.autoscrolltimer); } scrolltext.prototype.autoscroll = function() { if (this.direction == "up") { if (parseint(this.scrollcontent.scrolltop) >= parseint(this.scrollcontent.scrollheight) / 2) { this.scrollcontent.scrolltop = 0; } this.scrollcontent.scrolltop += this.amount; } else { if (parseint(this.scrollcontent.scrolltop) <= 0) { this.scrollcontent.scrolltop = parseint(this.scrollcontent.scrollheight) / 2; } this.scrollcontent.scrolltop -= this.amount; } if (parseint(this.scrollcontent.scrolltop) % this.lineheight != 0) { this.scrolltimer = settimeout(this.getfunction(this, "autoscroll"), this.delay); } else { this.autoscrolltimer = settimeout(this.getfunction(this, "autoscroll"), this.timeout); } } scrolltext.prototype.scroll = function(direction) { if (direction == "up") { if (this.scrollcontent.scrolltop == 0) { this.scrollcontent.scrolltop = parseint(this.scrollcontent.scrollheight) / 2; } this.scrollcontent.scrolltop -= this.amount; } else { this.scrollcontent.scrolltop += this.amount; } if (parseint(this.scrollcontent.scrolltop) >= parseint(this.scrollcontent.scrollheight) / 2) { this.scrollcontent.scrolltop = 0; } if (parseint(this.scrollcontent.scrolltop) % this.lineheight != 0) { this.scrolltimer = settimeout(this.getfunction(this, "scroll", direction), this.delay); } } scrolltext.prototype.getfunction = function(variable, method, param) { return function() { variable[method](param); } }