加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

js实现单行文本向上滚动效果例子代码

发布时间:2023-08-03 14:41:38 所属栏目:教程 来源:
导读:代码如下:

/***************滚动场次开始*****************/

function ScrollText(content, btnPrevious, btnNext, autoStart) {

this.Delay = 10;

this.LineHeight = 20;

this.Amo
代码如下:
 
/***************滚动场次开始*****************/
 
function ScrollText(content, btnPrevious, btnNext, autoStart) {
 
    this.Delay = 10;
 
    this.LineHeight = 20;
 
    this.Amount = 1;
 
    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;
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章