JRS: In article <11**********************@g47g2000cwa.googlegroups .com>
, dated Sun, 23 Oct 2005 16:47:47, seen in news:comp.lang.javascript,
cjl <cj****@gmail.com> posted :
Hey all:
Rather ill-mannered - are you an infant Merkin or just a wannabe?
In my script I have the following:
change_opacity (0, id);
for (var x = 0; x<=100; x=x+1)
{
change_opacity( x, id );
}
This works. I want to convert this to a "setTimeout" call, so that it
occurs more slowly. So I try:
change_opacity (0, id);
for (var x = 0; x<=100; x=x+1)
{
setTimeout( "change_opacity(" + x +"," + id + ")", 200 );
}
But it doesn't work. I'm stuck.
I expect it does work; it just does what you told it to do, instead of
what you wanted to so.
Your code sets, as fast as possible, 101 200 ms timeouts. Ideally, 200
ms later, they would all fire in corresponding sequence. In practice,
after about 200 ms, they'll fire probably in either the right order or
possibly the reverse order.
What you should do is to seek some clock code and modify it to not
continue after Number 100. In a clock, each second starts when the
previous one finishes; they do not all start at once. Presumably you
did not read the newsgroup FAQ thoughtfully?
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.