16、状态栏一条条显示字

16、状态栏一条条显示字

<!-- 要实现此效果需要 2 个步骤: -->

 

<!-- 1 步: -->

<!-- 把下面的代码加到<HEAD></HEAD>区域中: -->

 

<script language="JavaScript">

<!--

var speed = 10

var pause = 2000

var timerID = null

var bannerRunning = false

var ar = new Array()

ar[0] = " 欢迎光临"

ar[1] = " 如果你有什么好的建议或意见,请与我联系"

ar[2] = " 您所关注的就是我们所关注的"

ar[3] = " 再次感谢你的光临,谢谢"

var message = 0

var state = ""

clearState()

function stopBanner()

{

if (bannerRunning)

clearTimeout(timerID)

bannerRunning = false

}

function startBanner()

{

stopBanner()

showBanner()

}

function clearState()

{

state = ""

for (var i = 0; i < ar[message].length; ++i)

{

state += "0"

}

}

function showBanner()

{

if (getString())

{

message++

if (ar.length <= message)

message = 0

clearState()

timerID = setTimeout("showBanner()", pause)

bannerRunning = true

}

else

{

var str = ""

for (var j = 0; j < state.length; ++j)

{

str += (state.charAt(j) == "1") ? ar[message].charAt(j) : ""

}

window.status = str

timerID = setTimeout("showBanner()", speed)

bannerRunning = true

}

}

function getString()

{

var full = true

for (var j = 0; j < state.length; ++j)

{

if (state.charAt(j) == 0)

full = false

}

if (full)

return true

while (1)

{

var num = getRandom(ar[message].length)

if (state.charAt(num) == "0")

break

}

state = state.substring(0, num) + "1" + state.substring(num + 1, state.length)

return false

}

function getRandom(max)

{

return Math.round((max - 1) * Math.random())

}

// -->

</script>

 

 

 

<!-- 2 步: -->

<!-- <BODY>中的属性代码改为: -->

 

<BODY onload="startBanner()">

 

Write a comment

Comments: 0