pcx99 wrote:
ap**********@gmail.com wrote:
I am looking for a javascript function ( don't know what they call ths
) which will print a line of text, one letter at a time at a certain
speed until the full string is printed. Can this be done simply, and
is there a easy way to accomplish this? Sincerely, Jean
[snip example]
The example has all the ideas I would use. Below it is just changed a
little with a few suggestions that might help sometimes.
There is no need for the language attribute of the script tag. It is
deprecated.
<http://www.w3schools.com/tags/tag_script.asp>
The comment script hiding technique is not needed anymore. It was for
some browsers in 1995 or a similarly long time ago.
Use a doctype.
Use double quotes around attribute values for valid markup.
http://validator.w3.org/
In the following example the script in the head element could be in a
separate JavaScript file so that the browser can cache it.
The following uses the widely supported but non-standard innerHTML
property. This could be changed to standard compliant code.
The first argument to setTimeout can be a function or a string. I like
a function.
- Peter
---------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Marquee</title>
<script type="text/javascript">
function announce(id, str, period) {
var el = document.getElementById(id);
var pos = 0;
function doType() {
el.innerHTML = str.substring(0, ++pos);
if (pos < str.length) {
setTimeout(doType, period);
}
}
doType();
}
</script>
</head>
<body>
<div id="marqueeDiv"></div>
<script type="text/javascript">
announce('marqueeDiv', 'Insert your string here.', 200);
</script>
</body>
</html>