[jQuery] Re: I thought I understood threads...Works in Opera

2007-07-17 Thread PragueExpat


Sorry to be replying to my own threads, but this just gets more interesting.

Apparently, in IE and Firefox, the function must run to completion before
the UI is updated with any CSS / DOM changes, but in Opera, the UI is
updated immediately upon the jQ call.

I was trying to get a 'waiting' gif to appear at the beginning of a long
function call, but found that it was never appearing. I guess I need to
display the gif in a function before the long function. 




PragueExpat wrote:
 
 Why does the following function wait until after the while loop is
 finished to update the #timer css? It happens in IE and Firefox  - I'm
 (still) using jQ 1.1.2.
 
 function wait(time){
   $(#timer).css(display,block);
   time = time * 1000;
   var sleeping = true;
   var now = new Date();
   var startingMSeconds = now.getTime();
   while(sleeping){
 alarm = new Date();
 alarmMSeconds = alarm.getTime();
 if(alarmMSeconds - startingMSeconds  time){ sleeping = false; }
   }
 }
 

-- 
View this message in context: 
http://www.nabble.com/I-thought-I-understood-threads...-tf4096371s15494.html#a11648563
Sent from the JQuery mailing list archive at Nabble.com.



[jQuery] Re: I thought I understood threads...Works in Opera

2007-07-17 Thread Stephan Beal

On Jul 17, 2:42 pm, PragueExpat [EMAIL PROTECTED] wrote:
 Apparently, in IE and Firefox, the function must run to completion before
 the UI is updated with any CSS / DOM changes, but in Opera, the UI is
 updated immediately upon the jQ call.

Yeah, someone mentioned that behaviour a couple of days ago here in
the forum. The IE/FF behaviour is saner, IMO, because making 100% sure
that all JS/HTML elements are properly locked is, philosophically
speaking, impossible, once one considers that arbitrary browser
plugins and timer-triggered JS code can manipulate the DOM at
literally any microsecond.

 I was trying to get a 'waiting' gif to appear at the beginning of a long
 function call, but found that it was never appearing. I guess I need to
 display the gif in a function before the long function.

You could try using the blockUI jQuery plugin - it is designed for
just that type of thing. It blocks the user interface so the user
cannot click on anything while your operation is running.