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

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

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

復制代碼 代碼如下:

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

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";   //默認設置為文字向上滾動
}
/***************滾動場次結束*****************/

相關文章

  • JavaScript箭頭函數(shù)_動力節(jié)點Java學院整理

    JavaScript箭頭函數(shù)_動力節(jié)點Java學院整理

    這篇文章主要為大家詳細介紹了JavaScript箭頭函數(shù)的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • Webwork 實現(xiàn)文件上傳下載代碼詳解

    Webwork 實現(xiàn)文件上傳下載代碼詳解

    WebWork 當然也提供了很友好的攔截器來實現(xiàn)對文件的上傳,讓我們可以專注與業(yè)務邏輯的設計和實現(xiàn),在實現(xiàn)上傳和下載時順便關注了下框架上傳下載的實現(xiàn)
    2016-02-02
  • 利用d3.js力導布局繪制資源拓撲圖實例教程

    利用d3.js力導布局繪制資源拓撲圖實例教程

    這篇文章主要給大家介紹了關于如何利用d3.js力導布局繪制資源拓撲圖的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-01-01
  • 微信小程序對接七牛云存儲的方法

    微信小程序對接七牛云存儲的方法

    本篇文章主要介紹了小程序對接七牛云存儲的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • cypress e2e測試編寫注意點總結分析

    cypress e2e測試編寫注意點總結分析

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

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

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

    javascript textContent與innerText的異同分析

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

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

    這篇文章主要介紹了詳解微信小程序中的頁面代碼中的模板的封裝的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    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ù)是一個強大且多用途的工具,能夠對數(shù)組的元素進行排序,而漢字按照拼音排序又是一個常見需求,下面我們就來看看如何使用JavaScript實現(xiàn)漢字排序吧
    2023-12-12

最新評論