好学IT学院:IT信息技术分享交流平台
标签:JS  来源:互联网  作者:佚名  发布时间:2006-07-10  ★★★加入收藏〗〖手机版
摘要:1、跳动的文字把以下代码放在head/head之间:script language="JavaScript" ! Hide var speed = 10 var pause = 1500 var timerID = null var b……

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()">