Intensive JS Processing causes animated GIF to stop animating

  • Thread starter Chris Moltisanti
  • Start date
C

Chris Moltisanti

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
 
R

RobG

Chris said:
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 */
}
 
C

Chris Moltisanti

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
 
N

news.chello.nl

Perhaps have another window instance do the sort for you, like a hidden
iframe.
 
C

Chris Moltisanti

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top