Click to See Complete Forum and Search --> : type-writer simulating script


xataku_nakusute
07-25-2003, 03:01 PM
how can you make a script that while slowly type a message with a cursor?

im thinking it has something to do with changing the substr() or substring() values....but im not sure what to do

David Harrison
07-25-2003, 03:08 PM
Well here's the typewriter script, but for the cursor you may need an animation:

Edit:

Re-uploaded the attachment, there's a cursor but it doesn't flash.

xataku_nakusute
07-25-2003, 03:23 PM
im unsure of where to put a stop() function to stop the effect.....

im trying to make it so that when you go to type something in a textarea/input field, no matter what you type, its gonna say the message thats put into the typewriter script...

so onkeydown="write()" onkeyup="stopwrite()" and when you press a key again, it starts from where it left off

i remember seeing this script on scriptsearch.com i believe, but im unable to find it

David Harrison
07-25-2003, 03:29 PM
Gimme a minute, I think I can do that.

David Harrison
07-25-2003, 03:50 PM
Sossy it took so long, but I only just figured out how where to place the event handler.

xataku_nakusute
07-25-2003, 04:06 PM
thanx again for the help!!:D :D :D

David Harrison
07-25-2003, 04:16 PM
If you're interested I made the cursor flash.

xataku_nakusute
07-25-2003, 04:22 PM
:D :D :D Thanx man!:D :D :D

did you want me to give you some credit in the code?

David Harrison
07-26-2003, 01:06 PM
No thanks, I tend to stay away from the limelight. I'm just happy to help. :)

SlankenOgen
07-26-2003, 01:32 PM
The code you posted works fine for me, but I don't like it so I messed around with it and included a font specification :-|

<html>
<head>

<title>Typewriter</title>

<script type="text/javascript">


var content="::: This is a typewriter effect ::: ";
var lgn=content.length;
var disp="";
var n = 0;
var fA = "<font face = \"Courier New\">";
var fB = "|</font>";

function writestring(){

n = ++n%lgn;

disp = content.substr(0, n);

str = fA + disp + fB;


document.getElementById("string").innerHTML=str;


setTimeout("writestring()", ((Math.random() * 400)+80));
}

</script>

</head>

<body onload="writestring();">

<div id="string"></div>

</body></html>

David Harrison
07-26-2003, 01:43 PM
Rather than use the depreciated font tag, you can just do this:

<div id="string" style="font-family:'Courier new',sans-serif;"></div>

where sans-serif is a default family type in case Courier new is not installed on a particular users computer.

SlankenOgen
07-26-2003, 02:10 PM
Yep, that's correct, but I just rushed it off - I thought the original code was overly complicated and wanted to use substr() and a modulus as this seems a more natural way to do it.

David Harrison
07-26-2003, 02:16 PM
Well, just so's you know. :)