js實(shí)現(xiàn)單行文本向上滾動(dòng)效果實(shí)例代碼
/***************滾動(dòng)場次開始*****************/
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; //單排文字滾動(dòng)的高度
scrollup.Amount = 1; //注意:子模塊(LineHeight)一定要能整除Amount.
scrollup.Delay = 30; //延時(shí)
scrollup.Start(); //文字自動(dòng)滾動(dòng)
scrollup.Direction = "up"; //默認(rèn)設(shè)置為文字向上滾動(dòng)
}
/***************滾動(dòng)場次結(jié)束*****************/
相關(guān)文章
JavaScript箭頭函數(shù)_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要為大家詳細(xì)介紹了JavaScript箭頭函數(shù)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
Webwork 實(shí)現(xiàn)文件上傳下載代碼詳解
WebWork 當(dāng)然也提供了很友好的攔截器來實(shí)現(xiàn)對(duì)文件的上傳,讓我們可以專注與業(yè)務(wù)邏輯的設(shè)計(jì)和實(shí)現(xiàn),在實(shí)現(xiàn)上傳和下載時(shí)順便關(guān)注了下框架上傳下載的實(shí)現(xiàn)2016-02-02
利用d3.js力導(dǎo)布局繪制資源拓?fù)鋱D實(shí)例教程
這篇文章主要給大家介紹了關(guān)于如何利用d3.js力導(dǎo)布局繪制資源拓?fù)鋱D的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-01-01
cypress e2e測(cè)試編寫注意點(diǎn)總結(jié)分析
這篇文章主要為大家介紹了cypress e2e測(cè)試編寫注意點(diǎn)總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
基于jquery ajax的多文件上傳進(jìn)度條過程解析
這篇文章主要介紹了基于jquery ajax的多文件上傳進(jìn)度條過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09
javascript textContent與innerText的異同分析
因?yàn)榘l(fā)現(xiàn)網(wǎng)絡(luò)上很少有這方面的內(nèi)容,因此就把自己私有blog上的這篇文章搬出來到Boluor的公開blog,方便其它人查閱。2010-10-10
JavaScript使用sort函數(shù)實(shí)現(xiàn)漢字排序
JavaScript中的sort函數(shù)是一個(gè)強(qiáng)大且多用途的工具,能夠?qū)?shù)組的元素進(jìn)行排序,而漢字按照拼音排序又是一個(gè)常見需求,下面我們就來看看如何使用JavaScript實(shí)現(xiàn)漢字排序吧2023-12-12

