473,320 Members | 1,600 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,320 software developers and data experts.

Javascript "Concurrency"

I need the opposite of this. What I want to happen is the page loads, div_a hides after 3 seconds and then div_b hides after 3 more seconds. If I set both timeouts to 3 seconds, they happen together as if the clock starts from page load, not when the last event finished like other scripting, eg Python. I have to wait 3 seconds for the first and 6 seconds for the second per the last line of code.

Expand|Select|Wrap|Line Numbers
  1. var ta = 3000;
  2. var tb = 3000;
  3.  
  4. var hideDivA = function() {
  5.     $('#div_a').css({"display":"none"});
  6.     }
  7. var hideDivB = function() {
  8.     $('#div_b').css({"display":"none"});
  9.     }
  10.  
  11. setTimeout(hideDivA, ta);<!--wait 3 seconds-->
  12. setTimeout(hideDivB, ta+tb);<!--wait 3 more-->
  13.  
Oct 11 '11 #1
3 1950
Dormilich
8,658 Expert Mod 8TB
setTimeout() does not stop the script for the time given, it sets a countdown after which the given function is to be executed and then proceeds.
the simple solution for your case is to use a delay of 6 seconds on the second function.
Oct 11 '11 #2
Thanks for the reply! That makes perfect sense.

To add a bit to this, the project was supposed to be written in a digital signage software that is perfectly suited to this, but was moved to html5 (because it sounds fancy, seriously) by the customer and the boss went along with it, against all the programmers' advice :(. I'm stuck with it and learning under fire as we don't do html at all! I guess what I really need is a more single-threaded behavior, much like Python or VB script, so that I can manage a large number of automated events/animations more easily. Any ideas out there to accomplish this? I'm just this one piece away from figuring it out.
Oct 11 '11 #3
Rabbit
12,516 Expert Mod 8TB
Why not cascade the timeout?

Expand|Select|Wrap|Line Numbers
  1. var ta = 3000; 
  2. var tb = 3000; 
  3.  
  4. var hideDivA = function() { 
  5.     $('#div_a').css({"display":"none"}); 
  6.     setTimeout(hideDivB, tb);<!--wait 3 more--> 
  7.     } 
  8.  
  9. var hideDivB = function() { 
  10.     $('#div_b').css({"display":"none"}); 
  11.     } 
  12.  
  13. setTimeout(hideDivA, ta);<!--wait 3 seconds--> 
Oct 11 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul Moore | last post by:
I can't find anything which spells this out in the manuals. I guess that, at some level, the answer is "a single bytecode operation", but I'm not sure that explains it for me. This thought was...
3
by: dcrespo | last post by:
Hi all... Here is my infrastructure design of a "distributed" system: - Many (30-50) hosts connected via VPN to a server. - Each host manages a system that receives local data (stored in a local...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
4
by: Robin Tucker | last post by:
Hi, I'm currently implementing a database with a tree structure in a table. The nodes in the tree are stored as records with a column called "Parent". The root of the tree has a "NULL" parent....
10
by: Flip | last post by:
I know the int.Parse("123") will result in an int of 123, but what happens with a null? I believe it give a null exception (seems like I get either NullArgumentException or ArgumentNullException...
2
by: Jenna Schmidt | last post by:
I know that one of the benefits of using "Shared" methods is you do not explicitly have to Dim as New object to access the method. Are there some other implications with memory and concurrency...
6
by: Anders J | last post by:
Hi We have some code that runs in a EventReceiver ItemAdded handler. The code must be thread-safe since it is iterating a List to find the max number of a column and assigns it + 1 to the Item...
3
by: stefan.albert | last post by:
Hi folks, we have a little discussion about lock escalation... What is better for performance: To have an escalation "early" (smaller locklist) or aviod the escalation with a big lock list? ...
2
by: Royt | last post by:
Have a look at this site: http://blogs.msdn.com/vcblog/archive/2007/11/05/iso-c-standard-update.aspx C is a mature language used everywhere, it doesn't belong to any commercial company, should...
0
by: Roland Schwarz | last post by:
Most probably what I am asking for already has been answered somewhere, still I was not able to find:-( I want to encapsulate a class ( a primitive type for the beginning ) to behave like a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: 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.