欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實現(xiàn)單行文本向上滾動效果實例代碼

 更新時間:2013年11月28日 10:07:29   作者:  
這篇文章主要介紹了js實現(xiàn)單行文本向上滾動效果,大家參考使用吧

復(fù)制代碼 代碼如下:

/***************滾動場次開始*****************/

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;
        }
        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);
    }
}

if (document.getElementById("ul_round")) {
    var scrollup = new ScrollText("ul_round");
    scrollup.LineHeight = 40;        //單排文字滾動的高度
    scrollup.Amount = 1;            //注意:子模塊(LineHeight)一定要能整除Amount.
    scrollup.Delay = 30;           //延時
    scrollup.Start();             //文字自動滾動
    scrollup.Direction = "up";   //默認設(shè)置為文字向上滾動
}
/***************滾動場次結(jié)束*****************/

相關(guān)文章

  • cypress e2e測試編寫注意點總結(jié)分析

    cypress e2e測試編寫注意點總結(jié)分析

    這篇文章主要為大家介紹了cypress e2e測試編寫注意點總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-04-04
  • 基于jquery ajax的多文件上傳進度條過程解析

    基于jquery ajax的多文件上傳進度條過程解析

    這篇文章主要介紹了基于jquery ajax的多文件上傳進度條過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • javascript textContent與innerText的異同分析

    javascript textContent與innerText的異同分析

    因為發(fā)現(xiàn)網(wǎng)絡(luò)上很少有這方面的內(nèi)容,因此就把自己私有blog上的這篇文章搬出來到Boluor的公開blog,方便其它人查閱。
    2010-10-10
  • 詳解微信小程序中的頁面代碼中的模板的封裝

    詳解微信小程序中的頁面代碼中的模板的封裝

    這篇文章主要介紹了詳解微信小程序中的頁面代碼中的模板的封裝的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-10-10
  • JS中Safari瀏覽器中的Date

    JS中Safari瀏覽器中的Date

    在js中處理Date時,發(fā)現(xiàn)Safari和其他瀏覽器的支持方式不一致。下面通過本文給大家分享js中Safari瀏覽器中的Date,感興趣的朋友一起學習吧
    2017-07-07
  • JavaScript使用sort函數(shù)實現(xiàn)漢字排序

    JavaScript使用sort函數(shù)實現(xiàn)漢字排序

    JavaScript中的sort函數(shù)是一個強大且多用途的工具,能夠?qū)?shù)組的元素進行排序,而漢字按照拼音排序又是一個常見需求,下面我們就來看看如何使用JavaScript實現(xiàn)漢字排序吧
    2023-12-12
  • 最新評論