Suppose I had text from a div tag, for example:
<div id="outPutContainer"> <div id="contentDiv" style="display:none;"> This is some cool content... </div> </div>
Now, if I wanted to, I could create a JavaScript function that will print characters one at a time, and everything will work fine. An example is below.
function printSentence(inner, outer, index, speed) { var input = document.getElementById(inner).innerHTML; var timer = setInterval(function(){ document.getElementById(outer).innerHTML+=input.charAt(index); index++; if(index == sentence.length -1){ printResume(inner, outer, index+1, speed); }else{ clearInterval(timer); } }, speed); } printSentence("contentDiv", "outPutContainer", 0, 100);
Again, the above function works fine, however let me want to consider the html tags inside the element, how it will work. Example:
<div id="contentDiv2"> This is some cool <strong>content</strong> <p>Paragraph of content</p> </div>
Thus, the ideal effect would be
This is awesome content.
Paragraph of content
(The typewriter effect was inspired by Charlie) "I like giving credit where credit should be" (: Javascript print effect
I suggest that I can add jsFiddle to make it easier for people. http://jsfiddle.net/bJxe3/19/
source share