The main use of settimeout (), recursion and string.substring ();
The effect is like having a typist typing.
Method II: JavaScript to achieve typing effect of typewriting computer
<span id= "Demo" ></span>
<script defer>
var text= "javascript-implemented typing effect" //Predefined text
var delay=200 //text occurrence time interval
var i=0 //initialization variable i
function Scrollit () {
//Set the text within the object with the demo ID to start with 0 from the variable text to I Between the text plus "_"
Demo.innertext=text.slice (0,i++) + "_"
if (i>text.length) { //When I is greater than text length
i=0 //Reset I to 0, so that the text again from the first text appear
//delay to perform the scrollit () function, delay*10 is to allow the display of the full text of a little longer
settimeout ("Scrollit ()", delay*10)
}
//Otherwise execute scrollit () function
else settimeout ("Scrollit ()", delay)
after delay milliseconds Scrollit ()//Call Scrollit () function
</script>
Method Three: