Scrolling Message on Status Bar Example

Place all of the code in the HEAD part of the document.
First, initialize the variables.

MyMessage is the variable name. The message to be displayed is in quotes.

var MyMessage = "This is an example of a scrolling message.";

spaces is the variable name. A string of blank spaces (made by pressing the spacebar) is in quotes.

var spaces = " ";

The variable position is numeric and it stores the current position of the string. Initialize it with 0.

var position = 0;
Next, write the function.
Function is a keyword and is used to begin the function. ScrollingMessage() is the name of the function. A brace ( { ) is needed to begin the function. Be sure there is a space before the brace.

function ScrollingMessage() {

The window.status indicates there is going to be a display on the status bar. The display includes the message (MyMessage) which you want to begin at the very beginning (position 0), the spaces, and the message again.

window.status = MyMessage.substring(position, MyMessage.length) + spaces + MyMessage.substring(0, position);

The position is incremented by one. This can be written "position = position + 1". This gives the message the appearance of scrolling.

position++;

This checks to see if the position is larger than the length of the message. If it is, the position is reset to 0 and the message begins again.

if (position > MyMessage.length) position = 0;

The window.setTimeout method is used to run the function after a delay. This delay is set to .2 seconds. Increase this value to make the scrolling appear to be slower.

window.setTimeout("ScrollingMessage()",200);

The right brace ends the function.

}

This statement is used to call the function you just wrote.

ScrollingMessage();

The final code will look like this.

<SCRIPT LANGUAGE="JavaScript">
var MyMessage = "This is an example of a scrolling message.";
var spaces = "                     ";
var position = 0;

function ScrollingMessage() {
window.status = MyMessage.substring(position, MyMessage.length) + spaces + MyMessage.substring(0, position);
position++;
if (position > MyMessage.length) position = 0;
window.setTimeout("ScrollingMessage()",200);
}
ScrollingMessage();
</SCRIPT>

Go to Top of Page

Mailboxdgardner@twcny.rr.com

Copyright © 2001-2002 Deborah V. Gardner
DG Training Connection logo