複製程式碼如下:
/****************滾動場次開始*****************/
函數ScrollText(內容,btnPrevious,btnNext,autoStart){
這.延遲= 10;
這.LineHeight = 20;
這個.金額 = 1;
this.Direction = "向上";
this.超時= 1500;
this.ScrollContent = this.$(內容);
this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
//this.ScrollContent.scrollTop = 0;
如果(btn下一個){
this.NextButton = this.$(btnNext);
this.NextButton.onclick = this.GetFunction(this, "下一步");
this.NextButton.onmouseover = this.GetFunction(this, "停止");
this.NextButton.onmouseout = this.GetFunction(this, "開始");
}
如果(btn上一個){
this.PreviousButton = this.$(btnPrevious);
this.PreviousButton.onclick = this.GetFunction(this, "上一個");
this.PreviousButton.onmouseover = this.GetFunction(this, "停止");
this.PreviousButton.onmouseout = this.GetFunction(this, "開始");
}
this.ScrollContent.onmouseover = this.GetFunction(this, "停止");
this.ScrollContent.onmouseout = this.GetFunction(this, "開始");
如果(自動啟動){
this.Start();
}
}
ScrollText.prototype.$ = 函數(元素){
返回 document.getElementById(element);
}
ScrollText.prototype.Previous = function () {
清除超時(this.AutoScrollTimer);
清除超時(this.ScrollTimer);
this.Scroll("向上");
}
ScrollText.prototype.Next = function () {
清除超時(this.AutoScrollTimer);
清除超時(this.ScrollTimer);
this.Scroll("向下");
}
ScrollText.prototype.Start = function () {
清除超時(this.AutoScrollTimer);
this.AutoScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Timeout);
}
ScrollText.prototype.Stop = function () {
清除超時(this.ScrollTimer);
清除超時(this.AutoScrollTimer);
}
ScrollText.prototype.AutoScroll = function () {
if (this.Direction == "向上") {
if (parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2) {
this.ScrollContent.scrollTop = 0;
}
this.ScrollContent.scrollTop += this.Amount;
} 別的 {
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);
} 別的 {
this.AutoScrollTimer = setTimeout(this.GetFunction(this, "AutoScroll"), this.Timeout);
}
}
ScrollText.prototype.Scroll = 函數(方向){
if(方向==「向上」){
if (this.ScrollContent.scrollTop == 0) {
this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
}
this.ScrollContent.scrollTop -= this.Amount;
} 別的 {
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, "滾動", 方向), this.Delay);
}
}
ScrollText.prototype.GetFunction = 函數(變數、方法、參數){
返回函數(){
變數[方法](參數);
}
}
if (document.getElementById("ul_round")) {
var scrollup = new ScrollText("ul_round");
向上捲動.LineHeight = 40; //單排文字滾動的高度
向上捲動.Amount = 1; //注意:子模組(LineHeight)一定要能整除Amount。
向上滾動.Delay = 30; //延遲
向上捲動.Start(); //文字自動滾動
向上滾動.Direction = "向上"; //預設為向上文字滾動
}
/****************滾動場次結束*****************/