Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: setTimeout()??

  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setTimeout()??

    Any idea on how I might print to a page one letter at a time to make the appearence that it is coming from someone on a keyboard? I tried to put my text in an array and then using a for loop. In the for loop I used setTimeout and that was freakish.

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>57003</title>
    	</head>
    	<body>
    		<p id="console">&gt; </p>
    
    		<script type="text/javascript">
    			var console = document.getElementById('console');
    			var text = "I'm typing this to you from outer space";
    			var i = 0;
    
    			function printText()
    			{
    				console.firstChild.nodeValue += text.charAt(i++);
    
    				if(i < text.length)
    				{
    					setTimeout(printText, 50);
    				}
    			}
    
    			setTimeout(printText, 50);
    		</script>
    	</body>
    </html>
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    You may want to look at this old text typer script of mine.
    Attached Files Attached Files


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •