In this example I show how to add a bouncing message at the status bar of the browser.
Define the next variables :
o data - contains a message to be displayed
o limit - bounce limit
o message1
o direction
o speed
The function bounce() contains an if-else condition that bounces the message left or right.
To shift the message left we add two spaces to message1 and assign the value to message2 :
And repeat process to ‘*’ and set direction to the left :
if (message1.substring(message1.length-1,message1.length) == "*") direction="left";
in this way we can bounce our message at the status bar
Full Code
<SCRIPT language=JavaScript type="text/javascript">
<!--
var data = " My Bouncing Message ... !!! "; // Message to be display
var limit=" "; // define bounce limit
var message1=limit+'*'+data+'*'+limit;
var direction = "left";
var speed = 75;
function bounce()
{
if (direction == "left")
{
message2=message1.substring(2,message1.length)+" ";
window.status=message2;
setTimeout("bounce();",speed);
message1=message2;
if (message1.substring(0,1) == "*")
direction="right";
}
else
{
message2=" "+message1.substring(0,message1.length-2);
window.status=message2;
setTimeout("bounce();",speed);
message1=message2;
if (message1.substring(message1.length-1,message1.length) == "*")
direction="left";
}
}
bounce()
// -->
</SCRIPT>