javascript typing effect
-
I am trying a javascript typing effect. I am facing problem in giving delay between printing of two characters. I tried setTimeout but is not working as shown below: <!-- var str="good evening"; var ctr=0; function show() { while(ctr<str.length) { document.write(str.charAt(ctr)); <br>/* This is not working: setTimeout(document.write(str.charAt(ctr),50) */</b> ctr++; } } --> show(); Please help Ranjan Goyal
-
I am trying a javascript typing effect. I am facing problem in giving delay between printing of two characters. I tried setTimeout but is not working as shown below: <!-- var str="good evening"; var ctr=0; function show() { while(ctr<str.length) { document.write(str.charAt(ctr)); <br>/* This is not working: setTimeout(document.write(str.charAt(ctr),50) */</b> ctr++; } } --> show(); Please help Ranjan Goyal
Hi, This is what you need to do :
function show() { var typeLength= str.length document.typewriterScreen.typepage.value= document.typewriterScreen.typepage.value + str.charAt(i) i++ var timeID= setTimeout("show()",50) }
In my case typewritescreen is my form and typepage is my textarea. But you could use your document property. What's happen is that the codevar timeID= setTimeout("show()",50)
sets a time out for the script of 50/1000 of a second before it runs through the function again. Hopes this helps you out -
Hi, This is what you need to do :
function show() { var typeLength= str.length document.typewriterScreen.typepage.value= document.typewriterScreen.typepage.value + str.charAt(i) i++ var timeID= setTimeout("show()",50) }
In my case typewritescreen is my form and typepage is my textarea. But you could use your document property. What's happen is that the codevar timeID= setTimeout("show()",50)
sets a time out for the script of 50/1000 of a second before it runs through the function again. Hopes this helps you outI tried following and it is not working. But I can write on the status bar as shown below in commented portion. Moreover I don't want to write in the textbox but on the document. <!-- var str="good evening"; var i=0; function show() { var typeLength= str.length document.typewriterScreen.typepage.value= document.typewriterScreen.typepage.value + str.charAt(i) i++ var timeID= setTimeout("show()",50) /* //For printing on status bar if(ctr<=str.length) { window.status = str.substring(0, ctr++) + "_"; setTimeout("show()",200); if(ctr == str.length) { window.status = str.substring(0, ctr) + "_"; ctr=0; } } */ } -->
Please Help. Ranjan