复制代码代码如下:
/****************滚动场次开始*****************/
函数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 = "向上"; //默认设置为向上文字滚动
}
/****************滚动场次结束*****************/