473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Multiple setTimeout in function?

Max
Hi,

I'm not exactly sure why this doesn't work. I'm basically just trying a
simple approach at a slide down div.

function slide_div {
setTimeout("document.getElementById('mydiv').style .length='10px';",1000);

setTimeout("document.getElementById('mydiv').style .length='20px';",1000);

setTimeout("document.getElementById('mydiv').style .length='30px';",1000);

setTimeout("document.getElementById('mydiv').style .length='40px';",1000);

setTimeout("document.getElementById('mydiv').style .length='50px';",1000);

setTimeout("document.getElementById('mydiv').style .length='60px';",1000);

}

It seems like it just runs the last setTimeout line and pops out all at
once. I've even tried adding a=, b=, c=,. etc at the begining of each
line to no avail.

Anybody know a simple solution for this?

Thanks,
Max

Oct 10 '06 #1
6 10874

Max wrote:
Hi,

I'm not exactly sure why this doesn't work. I'm basically just trying a
simple approach at a slide down div.

function slide_div {
setTimeout("document.getElementById('mydiv').style .length='10px';",1000);

setTimeout("document.getElementById('mydiv').style .length='20px';",1000);

setTimeout("document.getElementById('mydiv').style .length='30px';",1000);

setTimeout("document.getElementById('mydiv').style .length='40px';",1000);

setTimeout("document.getElementById('mydiv').style .length='50px';",1000);

setTimeout("document.getElementById('mydiv').style .length='60px';",1000);

}

It seems like it just runs the last setTimeout line and pops out all at
once. I've even tried adding a=, b=, c=,. etc at the begining of each
line to no avail.

Anybody know a simple solution for this?

Thanks,
Max
Increment your milliseconds instead of using 1000 for all of them. e.g.
1000,2000,etc

Oct 10 '06 #2
Max wrote on 10 okt 2006 in comp.lang.javascript:
I'm not exactly sure why this doesn't work. I'm basically just trying a
simple approach at a slide down div.

function slide_div {
a function needs ()
setTimeout("document.getElementById
('mydiv').style.length='10px';",1000);
>
setTimeout("document.getElementById
('mydiv').style.length='20px';",1000);
>
setTimeout("document.getElementById
('mydiv').style.length='30px';",1000);
>
setTimeout("document.getElementById
('mydiv').style.length='40px';",1000);
>
setTimeout("document.getElementById
('mydiv').style.length='50px';",1000);
>
setTimeout("document.getElementById
('mydiv').style.length='60px';",1000);
>
}

It seems like it just runs the last setTimeout line and pops out all at
once. I've even tried adding a=, b=, c=,. etc at the begining of each
line to no avail.

They start all at [nearly] the same time,
so they all fire at [nearly] the same second later.
setTimeout() is NOT a wait() function.

Try:

==================================
var mydiv = document.getElementById('mydiv');
var myLength = 0;
slide_div();

function slide_div() {
mydiv.style.length= myLength + 'px';
myLength += 10;
if (myLength<=60)
setTimeout("slide_div()",1000);
};
===================================

not tested.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 10 '06 #3
Max


On Oct 10, 11:03 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Max wrote on 10 okt 2006 in comp.lang.javascript:
I'm not exactly sure why this doesn't work. I'm basically just trying a
simple approach at a slide down div.
function slide_div {a function needs ()
setTimeout("document.getElementById('mydiv').style .length='10px';",1000);
setTimeout("document.getElementById('mydiv').style .length='20px';",1000);
setTimeout("document.getElementById('mydiv').style .length='30px';",1000);
setTimeout("document.getElementById('mydiv').style .length='40px';",1000);
setTimeout("document.getElementById('mydiv').style .length='50px';",1000);
setTimeout("document.getElementById('mydiv').style .length='60px';",1000);


}
It seems like it just runs the last setTimeout line and pops out all at
once. I've even tried adding a=, b=, c=,. etc at the begining of each
line to no avail.They start all at [nearly] the same time,
so they all fire at [nearly] the same second later.
setTimeout() is NOT a wait() function.

Try:

==================================
var mydiv = document.getElementById('mydiv');
var myLength = 0;
slide_div();

function slide_div() {
mydiv.style.length= myLength + 'px';
myLength += 10;
if (myLength<=60)
setTimeout("slide_div()",1000);};================= ==================

not tested.
Thanks for the suggestions. This worked fine and I now understand what
I was doing wrong.

Max

Oct 10 '06 #4
Max wrote:
document.getElementById('mydiv').style.length='10p x'
Err, what's 'length'? I don't see this property at:
http://www.w3schools.com/css/css_reference.asp

Shouldn't it be 'width' or 'height', or am I missing something?

Robin
Oct 11 '06 #5
JRS: In article <11*********************@k70g2000cwa.googlegroups. com>,
dated Tue, 10 Oct 2006 08:47:52 remote, seen in
news:comp.lang.javascript, Max <ma*@kipness.composted :
>
Anybody know a simple solution for this?
FAQ 4.20.

It's a good idea to read the newsgroup and its FAQ. See below.
--
© 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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 11 '06 #6
JRS: In article <eg**********@gemini.csx.cam.ac.uk>, dated Wed, 11 Oct
2006 09:55:15 remote, seen in news:comp.lang.javascript, Robin
<an**@somewhere.composted :
>Max wrote:
>document.getElementById('mydiv').style.length='10 px'

Err, what's 'length'? I don't see this property at:
http://www.w3schools.com/css/css_reference.asp
Not the most reliable of sites, IIRC, but it should be OK here.
>Shouldn't it be 'width' or 'height', or am I missing something?
I'd suggest 'fontSize'. But specifying absolute font-sizes is generally
deprecated.

--
© 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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 11 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Knocked Wood | last post by:
Hi, I looked around and can't find anything on this at all and can not get it to work for IE. I'm trying to loop multiple sounds on a game, with three unique variables, when a link is clicked....
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: Athanasius | last post by:
Could someone shed some light as to why the following setTimeout function will not work on the Mac IE5.2? It does however work on PC(Forefox,Netscape,IE) & Mac(Safari,Firefox). Here is the script,...
4
by: johkar | last post by:
Why does this code work in IE and Firefox and the second example does not work in IE. While these are just sample scripts, my actual scripts will be transferring options from one multi-select list...
4
by: Matt Ratliff | last post by:
Hello, I would appreciate any assistance you have with the following problem: I have (as an example) an array of values as follows: arrayvalues=new Array("0001","0003","0005") where each is the...
1
by: quill | last post by:
Hi I am making a chatroom script and it appears that the problem seems to be that my setTimeout's are conflicting. The logic is as follows: Run a login check every x seconds Run a trigger...
1
by: Memphis Steve | last post by:
Is it possible to combine multiple javascipts into one file and then call that file from a linked URL in the head section of an XHTML file? Here are the two scripts I want to use with the...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
3
Atli
by: Atli | last post by:
Hi everybody. This is not so much a problem, since I have already managed to find a solution, but my solution requires the use of the eval() function, which I just hate to use. The problem is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.