Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep animated gif running while doing intense calculations

I have a page which does some intense and long lasting calculations in Javascript. I would like to have a loading animation to tell the user progress is being made. I have an animated gif now, but the whole browser window freezes (and the gif does not play) while the Javascript is running. Then when it's done, it unfreezes. The calculations must be client-side so they cannot be done on a server.

Is there a way to keep Javascript from freezing the page and stopping animations from playing while it's doing calculations?

like image 468
Seth Carnegie Avatar asked Sep 04 '11 16:09

Seth Carnegie


People also ask

How do you keep a GIF moving?

Click Browse to upload the GIF from your computer, or enter the URL next to Open From URL and click Go. Click Animation from the menu at the top. Click Edit GIF Animation. Click the drop-down menu next to Looping and choose how many times you want the GIF to loop.

How many seconds can a GIF last?

Uploads are limited to 15 seconds, although we recommend no more than 6 seconds. Uploads are limited to 100MB, although we recommend 8MB or less. Source video resolution should be 720p max, but we recommend you keep it at 480p. Keep in mind media will appear mostly on small screens or smaller messaging windows.

How do I make a GIF run automatically?

You can use a free extension called Google GIFs Chrome Extension or Google gifs autoplay to do that. This extension works silently in the background and plays all animated GIFs in the Google image search results.


2 Answers

You can also use HTML5 webworkers (Wikipedia) to run long running scripts in the background. It is just like multi threading for javascript.

It will work in latest browsers except IE.

Found a game using webworkers check it out

like image 180
Mridul Kashatria Avatar answered Sep 18 '22 07:09

Mridul Kashatria


You could split the work in little small pieces and use a setTimeout to to begin the next iteration, once the first has finished, that way the browser has a chance to update the user interface. (this is because the browser uses one single thread, so if it is busy doing js it can't do other things)

like image 27
stewe Avatar answered Sep 19 '22 07:09

stewe