471,881 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,881 software developers and data experts.

Intensive JS Processing causes animated GIF to stop animating

Hi,

I am executing a piece of javascript that does some intensive
processing (sorting large tables). This can take a good few seconds so
I have an animated gif as a progress bar to let the user know that
something is happening.
However, the GIF does not animate when the javascript is processing.
Anyone know why?
I am aware that animated GIFs stop animating when a page is loading,
but I am not loading the page here.

Hope someone can help,

Thanks

Chris

Jun 4 '06 #1
4 7944
Chris Moltisanti wrote:
Hi,

I am executing a piece of javascript that does some intensive
processing (sorting large tables). This can take a good few seconds so
I have an animated gif as a progress bar to let the user know that
something is happening.
However, the GIF does not animate when the javascript is processing.
Anyone know why?


JavaScript is single threaded, so what normally happens is that browsers
will not update the display until a script finishes - this is generally
a good idea. You can get around that by starting your gif, then
starting the sorting using setTimeout with a very short timeout (say 1ms).

e.g.

function startSort(){
/* start animated gif */
setTimeout('doSort()',1);
}

function doSort(){
/* sorting code */
}
--
Rob
Jun 4 '06 #2
Thanks for the reply.
I tried this and it doesnt work. If I set the timeout to 1000 ms then
my GIF is animated for 1 sec but it still stops after that until the JS
is finshed processing.....

Chris

Jun 5 '06 #3
Perhaps have another window instance do the sort for you, like a hidden
iframe.

"Chris Moltisanti" <bb******@gmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
Thanks for the reply.
I tried this and it doesnt work. If I set the timeout to 1000 ms then
my GIF is animated for 1 sec but it still stops after that until the JS
is finshed processing.....

Chris

Jun 5 '06 #4
Hey,

I tried this out and it doesnt seem to make a difference. When I call
the javascript in my iframe e.g. window.myIFrame.doSort();
this call is the still executed in the same thread as the othe
javascript. Therefore it will wait for the processing to continue befor
it updates the GUI.

Jun 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by ctrl+alt+delete | last post: by
3 posts views Thread by Altman | last post: by
10 posts views Thread by samuelberthelot | last post: by
4 posts views Thread by Jeff | last post: by
7 posts views Thread by Lemune | last post: by
reply views Thread by YellowAndGreen | last post: by

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.