如何在进行大量计算时保持动画 gif 运行 [英] How to keep animated gif running while doing intense calculations

查看:38
本文介绍了如何在进行大量计算时保持动画 gif 运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,可以用 Javascript 进行一些密集而持久的计算.我想要一个加载动画来告诉用户正在取得进展.我现在有一个动画 gif,但是在 Javascript 运行时整个浏览器窗口都冻结了(并且 gif 不播放).然后当它完成时,它会解冻.计算必须在客户端进行,因此无法在服务器上完成.

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.

有没有办法防止 Javascript 在计算时冻结页面并停止播放动画?

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

推荐答案

您也可以使用 HTML5 webworkers (Wikipedia) 在后台运行长时间运行的脚本.就像 javascript 的多线程一样.

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

它可以在除 IE 之外的最新浏览器中运行.

It will work in latest browsers except IE.

使用 webworkers 找到了一个游戏检查一下

Found a game using webworkers check it out

这篇关于如何在进行大量计算时保持动画 gif 运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆