分享
 
 
 

JAVASCRIPT 滚动字幕(支持添加多个)

王朝html/css/js·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

注: 在日文系统编写,所以用了我这乱七八糟的英文注释。Sorry!

JS文件:

//***********************************************************************************

// JavaScript HTML DIV scroll bar controler

//

// by mostone@hotmail.com 2005.06.15

//

// useage:

// create DIV scrollbar

// scroll directions: scroll up/ down/ left/ right

// setp 1:

// in HTML document, add a div tag and give "id" attribute

// setp 2:

// include this file into your HTML and etc document

// use "<script>" tag include src attribute

// setp 3:

// write your script

// exmple:

// var scrollBarControl = new scrollBar();

// scrollBarControl.addBar("myBarID", 100, 100, 50, "down");

// scrollBarcontrol.createScrollBars();

// finally:

// save your HTML document and test it.

//

//----------------------------------------------------------------------------------

// method:

// scrollBar()

// scrollBarControl class constrction

// without parameters

// addBar(barID, width, height, interval, direction)

// add user bar define

// parameters:

// barID (Required) String <DIV ID="xxx"> the id tag

// width (Optional) Integer that specifies the bar's width

// height (Optional) Integer that specifies the bar's height

// interval (Optional) Integer that specifies the number of milliseconds.

// direction (Optional) String that specifies the scroll direction

//

//***********************************************************************************

var __scrollBarControl = null;

function innerBarProp(barID, width, height, interval, direction)

{

this.barID = barID;

this.width = width;

this.height = height;

this.interval = interval;

this.direction = direction;

this.stopScroll = false;

this.maxValue = 0;

this.preValue = 0;

}

function scrollBar()

{

this.barsArray = new Array();

//save current object

__scrollBarControl = this;

}

//////////////////////////////////////////////////////////////////

// add scrollbar to bar list and set properties

// parameters:

// barID: HTML's tag <DIV>'s id property

// (for js access the DIV object)

// width: define the scrollbar's width

// height: define the scrollbar's height

// interval: define the scroll speed

// ( scroll up/down per XX millinSecond )

// direction: scroll direction's defined

// "up"

// "down"

// "left"

// "right"

//////////////////////////////////////////////////////////////////

scrollBar.prototype.addBar = function(barID, width, height, interval, direction)

{

//check parameters

var paraCount = arguments.length;

if ( paraCount < 1 )

{

alert("parameters count incorect!");

return;

//throw "parameters count inccorect!";

}

//width's default value

if ( typeof( width ) == "undefined" )

{

var width = 100;

}

//height's default value

if ( typeof( height ) == "undefined" )

{

var height = 100;

}

//interval's default value

if ( typeof( interval ) == "undefined" )

{

var interval = 1000;

}

//direction's default value

if ( typeof( direction ) == "undefined" )

{

var direction = "up";

}

//create scrollbar's inner properties

var barProp = new innerBarProp(barID, width, height, interval, direction);

var barCount = this.barsArray.length;

this.barsArray[barCount] = barProp;

}

scrollBar.prototype.createScrollBars = function()

{

//get bar's count

var barCount = this.barsArray.length;

//if no bar add to scrollControl do nothing

if ( barCount == 0 )

{

return;

}

//init scroll bars

for ( var i=0; i<barCount; i++ )

{

var objBarID = this.barsArray[i].barID;

//if typeof objBarID is object

// that's meaning it inited

//if typeof objBarID is string

// init that scroll bar

if ( typeof( objBarID ) == "string" )

{

//get scroll <DIV> object

var objBar = document.getElementById( objBarID );

if (objBar == null)

{

//objBarID is not exist

if ( document.readyState == "complete" || document.readyState == "loaded" )

{

//the objBarID not exists in current document

//throw "the objBarID is not exists.";

alert("ScrollBar[" + objBarID + "]: not exist!");

return;

}

else

{

//wait for document to load objBarID

window.setTimeout("__scrollBarControl.createScrollBars()",50);

//exit processing..........

//and wait next time callbak

return;

}

}

//update barID

this.barsArray[i].barID = objBar;

}

}

for ( var i=0; i<barCount; i++ )

{

this.innerInitBar(i);

}

}

scrollBar.prototype.innerInitBar = function (index)

{

//get properties

var barID = this.barsArray[index].barID;

var width = this.barsArray[index].width;

var height = this.barsArray[index].height;

var interval = this.barsArray[index].interval;

var direction = this.barsArray[index].direction;

var maxValue = 0;

//set scrollBar's properties

with(barID)

{

style.width = width;

style.height = height;

noWrap=true;

switch( direction )

{

case "up":

maxValue = Math.max(scrollHeight, height);

style.overflowX = "visible";

style.overflowY = "hidden";

var barHtml = innerHTML;

var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";

newHtml += " <tr>\n";

newHtml += " <td height='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " </tr>\n";

newHtml += " <tr>\n";

newHtml += " <td height='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " </tr>\n";

newHtml += "</table>\n";

innerHTML = newHtml;

break;

case "down":

maxValue = Math.max(scrollHeight, height);

style.overflowX = "visible";

style.overflowY = "hidden";

var barHtml = innerHTML;

var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";

newHtml += " <tr>\n";

newHtml += " <td height='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " </tr>\n";

newHtml += " <tr>\n";

newHtml += " <td height='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " </tr>\n";

newHtml += "</table>\n";

innerHTML = newHtml;

scrollTop = maxValue;

break;

case "left":

maxValue = Math.max(scrollWidth, width);

style.overflowX = "hidden";

style.overflowY = "visible";

var barHtml = barID.innerHTML;

var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";

newHtml += " <tr>\n";

newHtml += " <td width='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " <td width='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " </tr>\n";

newHtml += "</table>\n";

innerHTML = newHtml;

break;

case "right":

maxValue = Math.max(scrollWidth, width);

style.overflowX = "hidden";

style.overflowY = "visible";

var barHtml = innerHTML;

var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";

newHtml += " <tr>\n";

newHtml += " <td width='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " <td width='" + maxValue + "' valign='top'>\n";

newHtml += barHtml + "\n";

newHtml += " </td>\n";

newHtml += " </tr>\n";

newHtml += "</table>\n";

innerHTML = newHtml;

scrollLeft = maxValue;

break;

default:

//throw "direction is inccorect!";

alert("ScrollBar[" + id + "]: direction is incorect!");

return;

}

//set mouse events

onmouseover = new Function("__scrollBarControl.mouseEvt(" + index + ",true);");

onmouseout = new Function("__scrollBarControl.mouseEvt(" + index + ",false);");

window.setInterval("__scrollBarControl.scroll(" + index + ");",interval);

//save maxValue

this.barsArray[index].maxValue = maxValue;

}

}

scrollBar.prototype.mouseEvt = function(index, stop)

{

this.barsArray[index].stopScroll = stop;

}

scrollBar.prototype.scroll = function(index)

{

//get properties

var barID = this.barsArray[index].barID;

var width = this.barsArray[index].width;

var height = this.barsArray[index].height;

var interval = this.barsArray[index].interval;

var direction = this.barsArray[index].direction;

var stopScroll = this.barsArray[index].stopScroll;

var preValue = this.barsArray[index].preValue;

var maxValue = this.barsArray[index].maxValue;

if ( stopScroll == true ) return;

switch(direction)

{

case "up":

preValue++;

if ( preValue >= maxValue )

{

preValue = 0;

}

barID.scrollTop = preValue;

break;

case "down":

preValue--;

if ( preValue <= 0 )

{

preValue = maxValue;

}

barID.scrollTop = preValue;

break;

case "left":

preValue++;

if ( preValue >= maxValue )

{

preValue = 0;

}

barID.scrollLeft = preValue;

break;

case "right":

preValue--;

if ( preValue <=0 )

{

preValue = maxValue;

}

barID.scrollLeft = preValue;

break;

}

this.barsArray[index].preValue = preValue;

}

//=================end of file===========================

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有