help with setTimeout

  • Follow


Hey all:

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.

-CJL

0
Reply cjlesh (64) 10/23/2005 11:47:47 PM

Hey:

I just found this:

http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/8e71b67f28140f10/b4505d898bffb1b0?q=setTimeout&rnum=2&hl=en#b4505d898bffb1b0

Which sort of explains why I was having a problem.

I re-assigned my 'id' variable to a global, and now things are working.

-CJL

0
Reply cjl 10/24/2005 12:11:08 AM


cjl wrote:
> Hey all:
> 
> In my script I have the following:
> 
[...]

> 
> But it doesn't work.  I'm stuck.

See manu3d's post below for a much better version.

-- 
Rob
0
Reply RobG 10/24/2005 3:43:15 AM

RobG wrote on 24 okt 2005 in comp.lang.javascript:

> See manu3d's post below for a much better version.
> 

What is "below" on usenet, if it is not in your posting?

-- 
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

0
Reply Evertjan 10/24/2005 8:16:10 AM

JRS:  In article <1130111267.290164.188760@g47g2000cwa.googlegroups.com>
, dated Sun, 23 Oct 2005 16:47:47, seen in news:comp.lang.javascript,
cjl <cjlesh@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.
0
Reply Dr 10/24/2005 9:20:31 PM

Evertjan. wrote:
> RobG wrote on 24 okt 2005 in comp.lang.javascript:
> 
> 
>>See manu3d's post below for a much better version.
>>
> 
> 
> What is "below" on usenet, if it is not in your posting?
> 

Fair enough.  :-x

It was 'below' to me since I like the new stuff at the top and older 
stuff at the bottom, but maybe a link would have been better...


-- 
Rob
0
Reply RobG 10/24/2005 11:53:56 PM

John:

> Rather ill-mannered - are you an infant Merkin or just a wannabe?

Did you just call me a pubic hair wig? I guess a reply is in order.
Your mother is a toothless whore.

> 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.

I see.

> 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.

Now that it a helpful reply, thank you.  It seems I should apologize
for sullying the good name of your mother.

> Presumably you did not read the newsgroup FAQ thoughtfully?

Hmmm.  I tried to read it, but your mother kept begging me for another
shag.

-CJL

0
Reply cjl 10/25/2005 12:59:10 AM

6 Replies
105 Views

(page loaded in 0.107 seconds)

Similiar Articles:













7/13/2012 6:07:07 PM


Reply: