The example in this article describes how JavaScript achieves simple text print by word. We will share this with you for your reference. The details are as follows:
Let's take a look at the running effect:
The Code is as follows:
<!DOCTYPE>
<Title> www.jb51.net js typing effect </title> <meta charset= "utf-8" > <style type= "text/css" > div { width:980px; margin:10px auto; background: #F3E6EA; border:2px outset #f9c6aa; color:green; } </style> <script type= "text/javascript" > var i=1; function write() { var id=document.getElementById( "main" ); var msg= "JS typewriter effect, the principle is very simple: each time you get a string value to be played, output, overwrite the original output content to the JS typewriter effect, the principle is very simple: each time you get the value of a string to be typed, the output will overwrite the original output content to achieve the JS typewriter effect. The principle is very simple: each time you get the value of a string to be played, the output, the JS typewriter effect can be achieved by overwriting the original output content. The principle is very simple: the JS typewriter effect can be achieved by obtaining the value of a string to be output at a time and overwriting the original output content. The principle is very simple: each time you get the value of a string to be typed, the output will overwrite the original output content to achieve the JS typewriter effect. The principle is very simple: each time you get the value of a string to be played, the output, the JS typewriter effect can be achieved by overwriting the original output content. The principle is very simple: the JS typewriter effect can be achieved by obtaining the value of a string to be output at a time and overwriting the original output content. The principle is very simple: each time you get the value of a string to be typed, the output will overwrite the original output content to achieve the JS typewriter effect. The principle is very simple: each time you get the value of a string to be played, the output, overwrite the original output content" ; var len=msg.length; var msg1=msg.substring(0,i); id.innerHTML=msg1; if (i==len){clearInterval(t)} else i++; } function time1() { var t=setInterval( function (){write()},50); } </script> <body onload=time1()> <div id= "main" ></div> </body>