Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-01-2006, 08:45 PM   PM User | #1
limpsharp
New Coder

 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
limpsharp is an unknown quantity at this point
setTimeout() problems.

hi guys-

i'm working on a small idea and i would like to run this code:-
Code:
document.getElementById(id).style.height = origheight+"px";
after a set time period (about 20ms i guess ), however, the following line creates errors:-
Code:
var t1 = setTimeout("document.getElementById('+id+').style.height = '+origheight+'px' ",0.5);
any ideas why?
limpsharp is offline   Reply With Quote
Old 07-02-2006, 03:17 AM   PM User | #2
FuZion
Regular Coder

 
Join Date: May 2006
Posts: 152
Thanks: 5
Thanked 0 Times in 0 Posts
FuZion is an unknown quantity at this point
I'm rather new to JS, but I believe its the timing. You have 0.5, which Javascript reads as a half of a milisecond, and I'm not sure if Javascript can read decimals in that field. Anywho, 1000 miliseconds is equal to one second, so 5 seconds = 5000 or 30 seconds = 30,000.

Hope this helps,

FuZion
FuZion is offline   Reply With Quote
Old 07-02-2006, 06:23 AM   PM User | #3
subhailc
Regular Coder

 
Join Date: Jan 2004
Posts: 185
Thanks: 2
Thanked 1 Time in 1 Post
subhailc is an unknown quantity at this point
you're passing a statement to the setTimeout, which is looking for a function
Code:
//assuming you have "id" and "orignheight" already established globally
var t1=setTimeout(function(){document.getElementById(id).style.height=origheight+"px";},20);
subhailc is offline   Reply With Quote
Old 07-02-2006, 06:24 AM   PM User | #4
subhailc
Regular Coder

 
Join Date: Jan 2004
Posts: 185
Thanks: 2
Thanked 1 Time in 1 Post
subhailc is an unknown quantity at this point
and.. ms==millisecond - so 20ms isn't half a second - it's a fiftieth of a second. if you want half a second, change the 20 to 500.
subhailc is offline   Reply With Quote
Old 07-02-2006, 08:09 AM   PM User | #5
limpsharp
New Coder

 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
limpsharp is an unknown quantity at this point
Quote:
Originally Posted by subhailc
you're passing a statement to the setTimeout, which is looking for a function
Code:
//assuming you have "id" and "orignheight" already established globally
var t1=setTimeout(function(){document.getElementById(id).style.height=origheight+"px";},20);
Cheers fella - am i right in thinking this isn't the best way to run a statement after a set time?

And yeah, the 0.5 was a typo i meant to write 20.
limpsharp is offline   Reply With Quote
Old 07-02-2006, 09:15 AM   PM User | #6
subhailc
Regular Coder

 
Join Date: Jan 2004
Posts: 185
Thanks: 2
Thanked 1 Time in 1 Post
subhailc is an unknown quantity at this point
no, it's fine. the example i gave you should work.

... 20 milliseconds isn't noticeable. you probably want 500, which is half a second and still hardly a delay at all...
subhailc is offline   Reply With Quote
Old 07-02-2006, 09:55 AM   PM User | #7
limpsharp
New Coder

 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
limpsharp is an unknown quantity at this point
Quote:
Originally Posted by subhailc
no, it's fine. the example i gave you should work.

... 20 milliseconds isn't noticeable. you probably want 500, which is half a second and still hardly a delay at all...
it goes through possibly 1000 iterations so it makes for a nice smooth and quick transformation
limpsharp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:45 AM.


Advertisement
Log in to turn off these ads.