状态栏代码

个人日记

 1、在状态栏以打字形式出现

<body><script language="JavaScript">
var msg  = "欢迎来到彩霞湾    " ;
var interval = 120
var spacelen = 120;
var space10=" ";
var seq=0;
function Scroll() {
len = msg.length;
window.status = msg.substring(0, seq+1);
seq++;
if ( seq >= len ) { 
seq = 0; 
window.status = '';
window.setTimeout("Scroll();", interval );
}
else
window.setTimeout("Scroll();", interval );

Scroll();
</script>
</body>

 

2、文字接力效果


<head>
<script language="JavaScript">
<!--
function statusMessageObject(p,d) {
  this.msg = MESSAGE
  this.out = " "
  this.pos = POSITION
  this.delay = DELAY
  this.i     = 0
  this.reset = clearMessage
}
function clearMessage() {
  this.pos = POSITION
}
var POSITION = 100
var DELAY    = 5
var MESSAGE  = "欢迎你"
var scroll = new statusMessageObject()
function scroller() {
  for (scroll.i = 0; scroll.i < scroll.pos; scroll.i++) {
    scroll.out += " "
  }
  if (scroll.pos >= 0)
   scroll.out += scroll.msg
  else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length)
  window.status = scroll.out
  scroll.out = " "
  scroll.pos--
  if (scroll.pos < -(scroll.msg.length)) {
   scroll.reset()
  }
  setTimeout ('scroller()',scroll.delay)
}
function snapIn(jumpSpaces,position) {
  var msg = scroll.msg
  var out = ""
  for (var i=0; i<position; i++) 
    {out += msg.charAt(i)}
  for (i=1;i<jumpSpaces;i++) 
    {out += " "}
  out += msg.charAt(position)
  window.status = out
  if (jumpSpaces <= 1) {
    position++
    if (msg.charAt(position) == ' ') 
      {position++ }
    jumpSpaces = 100-position
  } else if (jumpSpaces >  3)
       {jumpSpaces *= .75}
  else
    {jumpSpaces--}
  if (position != msg.length) {
    var cmd = "snapIn(" + jumpSpaces + "," + position + ")";
    scrollID = window.setTimeout(cmd,scroll.delay);
  } else {
    window.status=""
    jumpSpaces=0
    position=0
    cmd = "snapIn(" + jumpSpaces + "," + position + ")";
    scrollID = window.setTimeout(cmd,scroll.delay);
    return false 
  }
  return true
}
snapIn(100,0);
// -->
</script>
</head>
 

3、状态栏慢慢计算PI值


<body>
<script>
<!--

function pi(name){
        this.init = init;
        this.compNext = p_compNext;
        this.printPi = p_printPi;
        this.computePi = p_computePi;
        this.runs = new Number();
        this.data = new Number();        
        this.sign = new Number();
        this.name = name;
        //this.init();
}

function init(){
        this.runs = -1;
     &nbs p;  this.data = 0;
        this.sign = -1;
}

function p_computePi(delay){
        //eval(this.name+".compNext();");
        this.compNext();
        if (this.runs %100 == 0) this.printPi();
        //eval(this.name+".printPi();");
        setTimeout(this.name + ".computePi("+delay+")",delay);
}

function p_printPi(){
        //document.pi.pivalue.value = this.data * 4;
        window.status = "[" + this.runs + "] > " + this.data * 4;
        //document.pi.runs.value = this.runs;
}

function p_compNext(){
        this.sign = parseInt(this.sign) * -1;
        this.runs = parseInt(this.runs) + 1;
        this.data += Math.pow((parseInt(this.runs) * 2 + 1),-1) * this.sign;
}

myPi = new pi("myPi");
myPi.init();
myPi.computePi(1);
//-->
</script>
</body>
 

4、状态栏标准时钟

<head>
<SCRIPT language="JavaScript">

        function doClock() {

                window.setTimeout( "doClock()", 1000 );

                today = new Date();

                self.status = today.toString();

    }

</SCRIPT>


<body bgcolor="#fef4d9" onLoad="doClock()">

5.状态栏登录时间

<body bgcolor="#fef4d9" onLoad="startClock()">
<script>

    var Temp;
    var TimerId = null;
    var TimerRunning = false;

    Seconds = 0
    Minutes = 0
    Hours = 0

    function showtime() 
    {
      if(Seconds >= 59) 
      {
        Seconds = 0
        if(Minutes >= 59) 
        {
          Minutes = 0
          if(Hours >= 23) 
          {
            Seconds = 0
            Minutes = 0
            Hours = 0
          } 
          else { 
            ++Hours 
          }
        } 
        else { 
          ++Minutes 
        }
      } 
      else { 
        ++Seconds 
      }

      if(Seconds != 1) { var ss="s" } else { var ss="" }
      if(Minutes != 1) { var ms="s" } else { var ms="" }
      if(Hours != 1) { var hs="s" } else { var hs="" }

      Temp = '你在本页停留了 '+Hours+' 小时'+', '+Minutes+' 分'+', '+Seconds+' 秒'+''
      window.status = Temp;
      TimerId = setTimeout("showtime()", 1000);
      TimerRunning = true;
    }
  
    var TimerId = null;
    var TimerRunning = false;

    function stopClock() {
      if(TimerRunning) 
        clearTimeout(TimerId);
        TimerRunning = false;
    }

    function startClock() {
      stopClock();
      showtime();
    }

    function stat(txt) {
      window.status = txt;
      setTimeout("erase()", 2000);
    }

    function erase() {
      window.status = "";
    }

</SCRIPT></body>
 

5、文字组合弹出 

<head>
<script language="javascript">

<!-- Hide this script from old browsers --

var speed = 10 

var pause = 1500 

var timerID = null

var bannerRunning = false

var ar = new Array()



ar[0] = "欢迎来到网站!  "

ar[1] = "欢迎光临专栏  "

ar[2] = "请多提意见,谢谢!    "



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

}

// -- End Hiding Here -->

</script>

<body bgcolor="#fef4d9" onLoad="startBanner()">

文字从右弹出
<head>

<script language="JavaScript">

   var MESSAGE  =   "  欢迎来到彩霞湾,请多提意见。谢谢!    "

   var POSITION = 150

   var DELAY    = 10

   var scroll = new statusMessageObject()

function statusMessageObject(p,d) {

  this.msg = MESSAGE

  this.out = " "

  this.pos = POSITION

  this.delay = DELAY

  this.i     = 0

  this.reset = clearMessage}

function clearMessage() {

  this.pos = POSITION}

function scroller() {

  for (scroll.i = 0; scroll.i < scroll.pos; scroll.i++) {

    scroll.out += " "}

  if (scroll.pos >= 0)

   scroll.out += scroll.msg

  else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length)

  window.status = scroll.out

  scroll.out = " "

  scroll.pos--

  if (scroll.pos < -(scroll.msg.length)) {

   scroll.reset()}

  setTimeout ('scroller()',scroll.delay)}

function snapIn(jumpSpaces,position) {

  var msg = scroll.msg

  var out = ""

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

    {out += msg.charAt(i)}

  for (i=1;i<jumpSpaces;i++) 

    {out += " "}

  out += msg.charAt(position)

  window.status = out

  if (jumpSpaces <= 1) {

    position++

    if (msg.charAt(position) == ' ') 

      {position++ }

    jumpSpaces = 100-position

  } else if (jumpSpaces >  3)

       {jumpSpaces *= .75}

  else

    {jumpSpaces--}

  if (position != msg.length) {

    var cmd = "snapIn(" + jumpSpaces + "," + position + ")";

    scrollID = window.setTimeout(cmd,scroll.delay);

  } else {    window.status=""

    jumpSpaces=0

    position=0

    cmd = "snapIn(" + jumpSpaces + "," + position + ")";

    scrollID = window.setTimeout(cmd,scroll.delay);

    return false }

  return true}

snapIn(100,0);

</script>

文章评论