An example of a scrolling message : Text HTML « HTML « JavaScript DHTML






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

1.Animating Text Styles
2.Moving Text
3.Using the TextRectangle Object Properties
4.Exploring the Bounding TextRange Properties
5.compareEndPoints() Method
6. Two Search and Replace Approaches (with Undo)
7.Using the document.selection Object
8.Encipher and Decipher