In this tutorial we show you how to type one letter at a time in you webpage with JavaScript. We make use of JavaScript functions to accomplish this tasks.
JavaScript Functions For Typing Animation
- split(“”) The split function will create an array from our string.
- shift() The shift function will shift the string one letter at a time.
- setTimeout() The setTimeout function will control the speed of our animation.
Coding Scripts For Application
[code]<html>
<head>
<title>Use Javascript To Type Out Text On Webpage</title>
</head>
<body>
<div id="type_text"></div>
<script>
var myText = ‘This text is being typed out with javascript’;
var myArray = myText.split("");
var loopTimer;
function frameLooper() {
if(myArray.length > 0) {
document.getElementById("type_text").innerHTML += myArray.shift();
} else {
clearTimeout(loopTimer);
return false;
}
loopTimer = setTimeout(‘frameLooper()’,70);
}
frameLooper();
</script>
</body>
</html>[/code]



2 Comments
in this video you told us how to show letter one by one but can you please tell what changes should be made in the scripting to repeat the entire text again and again as the function applies for once and than the text written stops
reply fast
There is a good answer to your question on Stack Overflow here on using JavaScript to type one word at a time instead of one letter at a time.