用JavaScript来控制状态栏
5、状态栏跑马灯效果
把以下代码放在<head></head>之间:
<SCRIPT LANGUAGE="JavaScript">
<!--
var speed = 50
var pause = 2000
var timerID = null
var bannerRunning = false
var ar = new Array()
ar[0] = "MESSAGE #1"
ar[1] = "MESSAGE #2"
ar[2] = "MESSAGE #3"
ar[3] = "MESSAGE #4"
var currentMessage = 0
var offset = 0
function stopBanner() {
if (bannerRunning)
clearTimeout(timerID)
bannerRunning = false
}
function startBanner() {
stopBanner()
showBanner()
}
function showBanner() {
var text = ar[currentMessage]
if (offset < text.length) {
if (text.charAt(offset) == " ")
offset++
var partialMessage = text.substring(0, offset + 1)
window.status = partialMessage
offset++
timerID = setTimeout("showBanner()", speed)
bannerRunning = true
} else {
offset = 0
currentMessage++
if (currentMessage == ar.length)
currentMessage = 0
timerID = setTimeout("showBanner()", pause)
bannerRunning = true
}
}
// -->
</SCRIPT>
把以下代码放在<body>中:
<body onLoad="startBanner()">