|
Status Bar AnimationThis simple program displays a messge in the status bar, writing the string one letter at a time starting from its first character. The what message is used is chosen by a random number. This random number is used as the index for an Array of messages, and it can never be the same as the one previously used. /* Periodically animate text in the status bar. The text will be * displayed one letter at a time from the left. */ var Messages; // Will be an Array to hold the Text that is displayed. var MsgCount; // The Number of Strings to be held in the Messages Array. var Interval; // Interval of time between messages. var MsgIndex; // This will hold the Array Index of the String currently in use. var oldMsgIndex; // This will hold the Index of the previously used Array member. var CurrentMsg; // The current String in use. var timerID; // A handle to the timer procedures. var PosInStr; // Substring index. var Direction; // Determines if Text is being displayed or wiped away. var MsgSubStr; // Substring of the String currently in use. function Start() { MsgCount = 3; Messages = new Array(MsgCount); Messages[0] = "Cheating is a gift a man can give to himself"; Messages[1] = "You must find the Jade Monkey before the next full moon."; Messages[2] = "The only thing we have to fear is fear itself"; Interval = 20000; Direction = "forward"; PosInStr = 0; MsgIndex = 0; oldMsgIndex = 0; GetMsg(); timerID = setTimeout("ShowTxt()", Interval); } function GetMsg() { do { MsgIndex = Math.round(Math.random() * MsgCount); } while (MsgIndex == oldMsgIndex); oldMsgIndex = MsgIndex; CurrentMsg = Messages[MsgIndex]; } function ShowTxt() { if (Direction == "forward") { PosInStr++; } else { PosInStr--; } switch (PosInStr) { case CurrentMsg.length : clearTimeout(timerID); Direction = "backward"; timerID = setTimeout("ShowTxt()", 3000); break; case 0 : clearTimeout(timerID); window.status = ""; GetMsg(); Direction = "forward"; timerID = setTimeout("ShowTxt()", Interval); break; default : MsgSubStr = CurrentMsg.substring(0, PosInStr); window.status = MsgSubStr; timerID = setTimeout("ShowTxt()", 100); } }
|
|