In this article we are going to design a JavaScript Left to right text scroll at windows Status Bar. Take a look below on piece of code¡
var YourMess = "TechXcel.com - provides technical excellence... ";
var space = "";
var msg = "";
var LeftMsg = "";
function MsgFLY(){
if (msg == "")
{
space = " ";
msg = YourMess;
LeftMsg = "";
}
if (space.length == 1)
{
while (msg.substring(0, 1) == " ")
{
LeftMsg = LeftMsg + space;
space = msg.substring(0, 1);
msg = msg.substring(1, msg.length);
}
LeftMsg = LeftMsg + space;
space = msg.substring(0, 1);
msg = msg.substring(1, msg.length);
for (var ii = 0; ii < 120; ii++)
{
space = " " + space;
}
}
else
space = space.substring(10, space.length);
window.status = LeftMsg + space;
timeout = window.setTimeout('MsgFLY()',100);
}
timeout = window.setTimeout('MsgFLY()',500);
timerId = setTimeout(script-to-execute, time-in-milliseconds);
As the MsgFLY() get called after every 500 milliseconds recursively. Here we have define 4 variables¡ YourMess, space,msg, Leftmsg. And then assign YourMess text to msg and a blank space to space. Now we are going to split our message to display at status bar by using msg.substring. msg.substring extracts characters
Syntax:
substring(A, [B])
Parameters:
A : An integer between 0 and one less than the length of the string.
B : (optional) An integer between 0 and the length of the string.
substring extracts characters from indexA up to but not including indexB. In particular:
If A equals B, substring returns an empty string.
If B is omitted, substring extracts characters to the end of the string.
If either argument is less than 0 or is NaN, it is treated as if it were 0.
If either argument is greater than stringName.length, it is treated as if it were stringName.length.
For example: -
// assumes a print function is defined
var anyString = "TechXcel";
// Displays "Tech"
print(anyString.substring(0,4));
And then we are adding blank space to it and then display it at status clock of web browser. see image below...
discuss this topic to forum
