Status Bar Scrolls Messages

[Total: 0    Average: 0/5]

This shows how to create a message in the window.status (defaultStatus) that scrolls the message out left to right. It then pauses for a momment and then begins again on the next string in the array it uses.

Body Code:

<script type=text/javascript>
var msgsdelay = 3000;  // msecs delay between messages
var chardelay = 100;   // msecs delay between characters in a message
var msgs = new Array()
    msgs[msgs.length?msgs.length:0] = "Hello World";
    msgs[msgs.length?msgs.length:0] = "Glad to see you";
    msgs[msgs.length?msgs.length:0] = "It's a beautiful day";
    msgs[msgs.length?msgs.length:0] = "Won't you be my neighbor?";

// this function ensures that only 1 delay count
// is going on at once.
function NewScrolling() {
  stopScroll();
  startScroll();
}
var timerID   = null;  // necessary to kill it.
var scrolling = false; // used to know if it is already going.
var msgNum    = 0;     // which message is being displayed.
var atchar    = 0;     // character currently displaying up to.
function stopScroll() {
  if (scrolling) {
    clearTimeout(timerID);
    scrolling = false;
  }
}

function startScroll() {
  if (atchar < msgs[msgNum].length) {
    if (msgs[msgNum].charAt(atchar) == " ") atchar++ 
    defaultStatus = msgs[msgNum].substring(0, (atchar++) + 1);
    timerID = setTimeout("startScroll()", chardelay);
  } else {
    atchar = 0; //reset to begining of next msg.
	msgNum = msgNum+1 == msgs.length?0:msgNum+1;// next message (around and around)
    timerID = setTimeout("startScroll()", msgsdelay);
  }
  scrolling = true;
}
</script>
<BR><a href="javascript:NewScrolling()">start text scrolling!</a>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *