473,499 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moving DIVs don't happen until end of function

Hi there, can anyone help please?

I have a calendar view made up of div tags for each day. I can
highlight a number of days in a column by clicking on one and holding
down shift and clicking on another one. each div tag is called "boxX_Y"
where Y is the column and X is the row. The javascript knows the first
clicked box, and the second and changes the style.className for the
boxes in between based on the Y value.

Trouble is, when selecting about 30 boxes it takes a while to change
the style.className, so I would like to display a message to say
"Please wait". I've done this by creating another div tag called
wait_message, and set the visibility to "visible" when the function to
highlight the boxes is called. However, the wait message box isn't
displayed until the loop for changing the classNames has finished, even
though the wait_message visibility code is above the loop.

Is there any way to make the code take effect straight away rather than
waiting for the whole function to be computed?

Toby

Oct 27 '06 #1
6 1312
VK
Is there any way to make the code take effect straight away rather than
waiting for the whole function to be computed?
Current UA's (even the most advanced ones) are having rather weak
graphics engines; so for "economy" purposes they update the graphics
context only after the end of the current script execution (and then
all changes applied in one bulk).
In order to overcome this you'll have to apply the "exit - re-enter"
trick using window.setTimeout:

function waitForLoad() {
displayWaitMessage();
window.setTimeout(proceedWithTheRest, 100);
}

function proceedWithTheRest() {
// the rest of operations
}

If waitForLoad / proceedWithTheRest are just stay-alone functions then
you are on the damn lucky side, this is all what you need.

If waitForLoad / proceedWithTheRest are methods of some custom object
then such "breaks" will reset [this] pointer back to Global object, so
you'll need different tricks to nail it somehow to the execution
context. There is a great number of such tricks, do not hesitate to ask
here.

Oct 27 '06 #2
If waitForLoad / proceedWithTheRest are methods of some custom object
then such "breaks" will reset [this] pointer back to Global object
One way around this is to create an anonymous function in the
setTimeout that calls the custom object's method, ie:

setTimeout(function(){myObject.someMethod(argument )}, 100);

This way, rather than setTimeout calling the method form its scope, it
simply tells the object to run its own method, placing it back into the
correct 'this' scope of the custom object.

This is also a good way to pass arguments to functions via setTimeout.

Oct 27 '06 #3
to**@mkkbb.f9.co.uk wrote:
<snip>
Trouble is, when selecting about 30 boxes it takes a while
to change the style.className, so I would like to display
a message to say "Please wait".
<snip>

Setting 30 class names really should not take a significant amount of
time. If you were setting 1000 an issue would not be unexpected but 30 is
just too few to be experiencing problems. it seems likely that improving
the efficiency of your code would negate this issue entirely.

Richard.
Oct 27 '06 #4

VK wrote:
In order to overcome this you'll have to apply the "exit - re-enter"
trick using window.setTimeout:

Thanks very much. Answered all my queries. I was trying to update
hundreds of cells rather than tens, so it wasn't really my code being
inefficient, but i've made comprises so that it works well now.

Great idea with the timeouts VK, i'll keep that in mind for future
projects too.

Oct 31 '06 #5

to**@mkkbb.f9.co.uk wrote:
VK wrote:
In order to overcome this you'll have to apply the "exit - re-enter"
trick using window.setTimeout:


Thanks very much. Answered all my queries. I was trying to update
hundreds of cells rather than tens, so it wasn't really my code being
inefficient, but i've made comprises so that it works well now.
My ancient 800MHz G4 can do 480 divs in about 0.12 seconds with
unoptimised code, you should be able to do a few hundred without any
need for a "please wait" sign. I'll post the code if you want.
Great idea with the timeouts VK, i'll keep that in mind for future
projects too.
A common trick, search the archives.

--
Rob

Oct 31 '06 #6
ASM
RobG a écrit :
to**@mkkbb.f9.co.uk wrote:
>Thanks very much. Answered all my queries. I was trying to update
hundreds of cells rather than tens, so it wasn't really my code being
inefficient, but i've made comprises so that it works well now.

My ancient 800MHz G4 can do 480 divs in about 0.12 seconds with
unoptimised code, you should be able to do a few hundred without any
need for a "please wait" sign. I'll post the code if you want.
all depends what you do, no ?

Example (very very heavy file of 3228 octets ... or 4ko) :
http://perso.orange.fr/stephane.mori...caracteres.htm
more than 1mn to display (G4 1.25Mhz) ! !

I don't think it is a problem with JS but much more a problem of
quantity of work the browser has to do to display tables.

Nov 1 '06 #7

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

Similar topics

3
25726
by: Peter Jenkins | last post by:
I have some divs I am using to get a two column layout for a section of a page, like so; <div1> <div2> <div3> blah blah blah blah blah blah blah blah...
20
2845
by: Firas D. | last post by:
http://firasd.org/ The divs of the 'box' class seem to have the effect I want in IE (namely: consistent height and horizontal alignment along the set of divs), but it totally falls apart in...
12
6256
by: deko | last post by:
Is there any way to work around the blank space created by hidden divs? I'm trying to use a relatively postioned divs with show/hide behaviors to annotate an image. The divs show/hide...
39
3558
by: WindAndWaves | last post by:
Hi Gurus I have a page, which looks a bit like this: .... <body> <div ID=id1>................</DIV> <div ID=gsd>................</DIV> <div ID=ewd>................</DIV> <div...
1
12080
by: tabert | last post by:
I want to use JavaScript when a button is clicked to show and hide a SPAN or DIV. This works in both IE and Netscape, but what I'd like to happen is for there to be no white space where the hidden...
3
3274
by: Cartoper | last post by:
I would like to design a web page as follows: There is a box (box A) with some things in it that the user can click on. When an item is clicked, another box (box B) moves in from the right side...
11
7816
by: dusk | last post by:
Hi, I'm very new to javascript, and I'm having trouble finding a way to display a string of divs without the code getting really messy. I have several different pages to write, each with about...
15
2416
by: mcjason | last post by:
I saw something interesting about a grid pair puzzle problem that it looks like a machine when you find each that work out the way it does and say with all the others that work out the way they...
6
19308
Motoma
by: Motoma | last post by:
Hello all! My end goal is to create an HTML layout that will expand and contract with the window size, while maintaining a variable number of content columns. In the example below, you will see...
0
7134
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,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
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...
1
6905
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...
0
7395
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...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.