Ejemplos en Javascript

Mensajes tipo máquina de escribir

Mensaje que va apareciendo como si saliera de una máquina de escribir (un carácter a la vez) dentro de un campo texto de form. Hay dos botones para controlar la dirección y velocidad del texto.

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo prÃ?Æ?Ã?¡ctico </TITLE>

<SCRIPT>
<!--- Hide script from old browsers
var msg = "it even re-sizes itself to fit your message!"
var x = ""
num = 1
toggle = 1
tt = 1
OOK = 0
timval = 60
var tval = ""
function switcha() {
   if (document.myform.dowhat.value == "Start/Stop" )
     tval = "Forward/Backward"
   if (document.myform.dowhat.value == "Forward/Backward")
     tval = "Fast/Slow"
   if (document.myform.dowhat.value == "Fast/Slow")
     tval = "Start/Stop"
   document.myform.dowhat.value = tval
}
function switcha2() {
   if (document.myform.dowhat.value == "Start/Stop" ) toggla()
   if (document.myform.dowhat.value == "Forward/Backward" ) csd()
   if (document.myform.dowhat.value == "Fast/Slow" ) fasl()
}
function fasl() { timval = (timval==60 ? 150 : 60 ) }

function csd() {
   tt = ( tt==1 ? 0 : 1)
}
function scroll() {
  if (tt==1)
    if (num <= msg.length)
      OOK = 1
  if (tt==0)
    if (num >

= 0)
      OOK = 1

  if ( OOK == 1)
 {
 OOK = 0
 x = msg.substring(0,num)
 document.myform.scroll.value = x
 num = ( tt==1 ? num+1 : num-1 )
 }
  else
 {
 x = ""
 document.myform.scroll.value = ""
 num = (tt==1 ? 0 : msg.length )
 }
  if (toggle == 1)
 setTimeout("scroll()", timval)
}
function toggla() {
 toggle = (toggle == 1 ? 0 : 1 )
 if (toggle == 1) scroll()
}

// end hiding from old browsers -->
</SCRIPT>


</HEAD>

<BODY bgcolor="white" onLoad="scroll()">


<FORM NAME="myform">
<INPUT TYPE="text" NAME="scroll" SIZE=&{msg.length + 2}; >
<BR><BR>
<INPUT TYPE="button"  VALUE="Do It" onClick="switcha2()">
<INPUT TYPE="text" NAME="dowhat" SIZE = 10 VALUE = "Start/Stop">
     
<INPUT TYPE="button" VALUE="next" onClick="switcha()" >
</FORM>



</body>
</html>

Animaci?exto