Posted By

pablobablo on 04/25/10


Tagged

teletype


Versions (?)

Teletype Text in JavaScript


 / Published in: JavaScript
 

  1. function teletype(id, text)
  2. {
  3. function typechar( char )
  4. {
  5. if ( char == '◄' && document.getElementById(id).innerHTML >= 1)
  6. {
  7. document.getElementById(id).innerHTML = document.getElementById(id).innerHTML.substr(0, document.getElementById(id).innerHTML.length-1);
  8. }
  9. else
  10. {
  11. document.getElementById(id).innerHTML += char;
  12. }
  13. }
  14.  
  15. var counter = 0;
  16. for( var i=0; i<text.length; i++ )
  17. {
  18. setTimeout(function()
  19. {
  20. var char = text[counter];
  21. typechar(char);
  22. counter++;
  23. },
  24. 50 * i);
  25. }
  26. }

Report this snippet  

You need to login to post a comment.