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

1、跳动的文字

把以下代码放在<head></head>之间:

<script language="JavaScript">
<!-- Hide
var speed = 10 
var pause = 1500 
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 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>

把以下代码放在<body>中:
<body onLoad="startBanner()">

2、文本变换

把以下代码放在<head></head>之间:
<script language="JavaScript">
function update(msg) {
      var pad_str="";
      n = msg.length;
      if(n<81) {
              pad = (81-n)/2;
              for(var i=0; i<pad; i++) {
                      pad_str+=" ";
              }      
      }      
      CurrentMsg = pad_str + msg;
      document.messages.field.value = CurrentMsg;
      clearTimeout(timer);
      timer = setTimeout("idleMsg()",5000);
}      
function MakeArray(n) {
      this.length=n;
      for(var i = 1; i<= n; i++) {
              this[i] = "";
      }
      return(this);
}
var index = 1;
var notice_num = 4;
var notices = new MakeArray(notice_num);
notices[1] = "MESSAGE #1";
notices[2] = "MESSAGE #2";
notices[3] = "MESSAGE #3";
notices[4] = "MESSAGE #4";

function idleMsg() {
      update(notices[index++]);
      if(index>notice_num) { index=1; }
}
</script>
把以下代码放在HTML文件任意地方:
<form name="messages" onSubmit="return false">
<input type="text" name="field" size=60 height=5 value="">
</form>

评论:RSS的力量
  有则笑话:一只母狼追赶一只白色公兔,公兔从数杈间逃走,母狼紧随其后。很不幸,母狼被卡住了,公兔遂强奸母狼迅速逃跑,母狼大怒挣脱后去…
  • 好学考试H5触屏版开放内测
  • 好学触屏公众号虎力全开、杨帆起航!