Click to See Complete Forum and Search --> : Anyone have examples for making text 'type' on the screen


Jonj1611
08-28-2004, 03:42 PM
Hi, I am very new to javascript and web page creation in general but was wondering if you guys/gals could help me. I am looking for a javascript that will make text look like it is typing on the screen quite quickly, you know the type of thing like when you see computers in films reading out data on the screen. Anyone know of such a script, thanks all!! :)

steelersfan88
08-28-2004, 04:00 PM
For a lousy example:<script type="text/javascript">

var ct = 0;
var str = "Just because something doesn't do what you planned it to do doesn't mean it's useless."
var inte;

window.onload = function() {
inte = setInterval(showTxt,75)
}

function showTxt() {
if(ct <= str.length) {
var toShow = str.substr(0,ct);
document.getElementById('txt').firstChild.data = toShow + ((toShow == str) ? "" : "|");
ct++;
}
else {
clearInterval(inte);
}
}

</script>

<div id="txt">Quote here ...</div>Lousy, Dr. Script

EDIT: var name

Jonj1611
08-28-2004, 04:04 PM
Thanks Dr Script, thats exactly the thing I am looking for!! Thanks again!

steelersfan88
08-28-2004, 04:06 PM
Sure, glad to help :D

Jonj1611
08-28-2004, 04:08 PM
Sorry about this just a quick question, as I said it works fully no problems there, but I have a mouse over script already running on the page I want to place the text script on, how do I seperate the scripts, ie allow two scripts to run on the same page, is it possible? Thanks :D

steelersfan88
08-28-2004, 04:16 PM
It is possible. Find your body tag with onload="...". Then, take the ... and move it inside ofwindow.onload = function() {
// add it here
// code already here goes here
}Dr. Script

Jonj1611
08-28-2004, 04:24 PM
Thanks again Dr.Script!

Jonj1611
08-28-2004, 04:34 PM
Doh!! Is it possible to have it write on more than one line? I am pretty sure that is the last question:rolleyes:

steelersfan88
08-28-2004, 05:09 PM
<script type="text/javascript">

// as many 0s here as number of quotes
var ct = [0,0];
// quotes here
var str = ["Just because something doesn't do what you planned it to do doesn't mean it's useless.",
"My way of joking is to tell the truth. It is the funniest joke in the world."]

window.onload = function() {
// other thing here
inte = setInterval(showTxt,75)
}

function showTxt() {
for(var i=0,toShow;i<ct.length;i++) {
if(ct[i] <= str[i].length) {
toShow = str[i].substr(0,ct[i]);
document.getElementById('txt').childNodes[i].firstChild.data = toShow + ((toShow == str[i]) ? "" : "|");
ct[i]++;
}
}
}

</script>

<div id="txt">
<!-- As many div elements here as quotes -->
<div>Quote 1</div>
<div>Quote 2</div>
</div>Dr. Script

steelersfan88
08-28-2004, 05:12 PM
The script doesn't work on Mozilla ... sorry, no time to fix it for now (that will get rid of another 3% in addition to like 17% or so with non-JS browsers).

If I misunderstood you, and you wnat 1 quote on two lines, set the width property of the style attribute of the div element, and then it will eventually go to two lines. Also set overflow to visible.

Jonj1611
08-28-2004, 05:39 PM
Hi Dr Script, you are the man, thanks for your help...............again.

Jonj1611
08-28-2004, 05:51 PM
Hi Dr Script, I get this error when I try and run it in IE 6

See Attachment

Don't worry if you can't sort it, at least the other one works great. :)

steelersfan88
08-28-2004, 09:02 PM
The second script has the error? Well, the error occurs in Mozilla as well, so I wouldn' recommend its use ...

Jonj1611
08-29-2004, 04:08 AM
Hi Dr. Script, many thank for trying! Don't worry, I can make use of the excellent first script, sorry for the delay in my reply I am in the UK so I have been to bed!! Thanks again.