How to keep animated gif running while doing intense calculations

后端 未结 7 1494
一向
一向 2020-12-06 05:15

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 a

相关标签:
7条回答
  • 2020-12-06 05:56

    Javascript processing is single threaded, so while your code is running, no other animation code will run.

    You'll need to set up your processing to run in batches. I don't know what you are processing, but if you are doing something that can be divided up easily, then you can process the first N items, then use setTimeout to schedule the next chunk to run in a few milliseconds. That way, you give the browser time to do other stuff that needs to be done.

    0 讨论(0)
提交回复
热议问题