Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. /** make text appear in the innerHTML of the element, one character at a time per timeBetween */
  2. function appearChars(str, elem, timeBetween) {
  3. var index = -1;
  4. (function go() {
  5. if (++index < str.length) {
  6. p.innerHTML = p.innerHTML + str.charAt(index);
  7. setTimeout(go, timeBetween);
  8. }
  9. })();
  10. }
  11.  
  12. // example
  13. var str = 'A wild text appears.';
  14. var elem = document.getElementsByTagName('p')[0];
  15. var timeBetween = 42;
  16.  
  17. appearChars(str, elem, timeBetween);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement