By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Multiple setTimeout in function?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.