An example of a scrolling message
/*
Javascript Essentials
by Jason J. Manger
Publisher: Mcgraw-Hill Osborne Media;
ISBN: 0078822343
*/
<!--
Program 10-6
-->
<html>
<head>
<script language="JavaScript">
<!--
var timerId;
var msg = "This is an example of a scrolling message";
var counter = 0;
// Is the timer already running?
if (timerId != null)
clearTimeout(timerId);
function pad() {
var padding = "";
// Prepend 50 spaces to the message:
for (var n=0; n <= (50 + msg.length); n++)
padding += " ";
return(padding);
}
function scroll() {
newMsg = pad() + msg + " ";
document.forms[0].elements[0].value =
newMsg.substring(counter, newMsg.length);
if (counter == newMsg.length) {
counter = 0;
}
counter ++;
timerId = setTimeout("scroll()", 1);
return true;
}
//-->
</script>
</head>
<body onLoad="scroll()">
<form>
<center>
<input type="text" size=70>
</center>
</form>
</body>
</html>
Related examples in the same category