Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** make text appear in the innerHTML of the element, one character at a time per timeBetween */
- function appearChars(str, elem, timeBetween) {
- var index = -1;
- (function go() {
- if (++index < str.length) {
- p.innerHTML = p.innerHTML + str.charAt(index);
- setTimeout(go, timeBetween);
- }
- })();
- }
- // example
- var str = 'A wild text appears.';
- var elem = document.getElementsByTagName('p')[0];
- var timeBetween = 42;
- appearChars(str, elem, timeBetween);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement