473,769 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("doc ument.getElemen tById('mydiv'). style.length='1 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='2 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='3 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='4 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='5 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='6 0px';",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 10921

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("doc ument.getElemen tById('mydiv'). style.length='1 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='2 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='3 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='4 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='5 0px';",1000);

setTimeout("doc ument.getElemen tById('mydiv'). style.length='6 0px';",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.javas cript:
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("doc ument.getElemen tById
('mydiv').style .length='10px'; ",1000);
>
setTimeout("doc ument.getElemen tById
('mydiv').style .length='20px'; ",1000);
>
setTimeout("doc ument.getElemen tById
('mydiv').style .length='30px'; ",1000);
>
setTimeout("doc ument.getElemen tById
('mydiv').style .length='40px'; ",1000);
>
setTimeout("doc ument.getElemen tById
('mydiv').style .length='50px'; ",1000);
>
setTimeout("doc ument.getElemen tById
('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.getEle mentById('mydiv ');
var myLength = 0;
slide_div();

function slide_div() {
mydiv.style.len gth= myLength + 'px';
myLength += 10;
if (myLength<=60)
setTimeout("sli de_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.net wrote:
Max wrote on 10 okt 2006 in comp.lang.javas cript:
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("doc ument.getElemen tById('mydiv'). style.length='1 0px';",1000);
setTimeout("doc ument.getElemen tById('mydiv'). style.length='2 0px';",1000);
setTimeout("doc ument.getElemen tById('mydiv'). style.length='3 0px';",1000);
setTimeout("doc ument.getElemen tById('mydiv'). style.length='4 0px';",1000);
setTimeout("doc ument.getElemen tById('mydiv'). style.length='5 0px';",1000);
setTimeout("doc ument.getElemen tById('mydiv'). style.length='6 0px';",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.getEle mentById('mydiv ');
var myLength = 0;
slide_div();

function slide_div() {
mydiv.style.len gth= myLength + 'px';
myLength += 10;
if (myLength<=60)
setTimeout("sli de_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.getEle mentById('mydiv ').style.length ='10px'
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************ *********@k70g2 000cwa.googlegr oups.com>,
dated Tue, 10 Oct 2006 08:47:52 remote, seen in
news:comp.lang. javascript, Max <ma*@kipness.co mposted :
>
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.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 11 '06 #6
JRS: In article <eg**********@g emini.csx.cam.a c.uk>, dated Wed, 11 Oct
2006 09:55:15 remote, seen in news:comp.lang. javascript, Robin
<an**@somewhere .composted :
>Max wrote:
>document.getEl ementById('mydi v').style.lengt h='10px'

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.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
4674
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. Something like... <Script Language="JavaScript"> <!-- function playSound(soundName, loops, timeLength){
3
14949
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
4672
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, it should simply present an alert message after 5 seconds. Thanks. <html> <head> <script language="javascript"> function MsgTimer() { var self = this;
4
3238
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 to another. I want the most recently added one to scroll into view. Works in both: <html> <head> <title>test</title> </head>
4
2477
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 value of an option in a select statement: <select id="usertypes" multiple="multiple"> <option value="0033">data1</option>
1
2919
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 check every x seconds
1
2413
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 instructions on where to normally place them in an XHTML document: SCRIPT #1: Step 1: Insert the below anywhere into the <body> section of your page where you wish the clock to be displayed:<script> /* Live Date Script-
3
3927
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 messing up. Problems:
3
3030
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 this. I have an object that has a function. This function needs to call itself in a setTimeout call. Using the "this" keyword from within the callback function will obviously not work, seeing as it would reference the new function rather than the...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.