使用 HTML5 创建加载屏幕
我在寻找一个合适的教程来生成 HTML5 的加载样式屏幕时遇到了一些问题。老实说,我不确定从哪里开始...
我的项目本质上是一个简单的 HTML5 游戏,我将在其中加载各种精灵表和图块集。它们会相当小,但我想在加载所有资源时显示一个小的加载旋转器而不是空白屏幕。
如果有人能给我指出正确的方向,无论是体面的链接还是代码示例来帮助我前进,我将不胜感激……我的 Google-fu 今天缺乏!
为了澄清起见,我需要弄清楚如何加载资源本身,而不是寻找微调器。例如,如何计算X%已加载。
编辑2
愚蠢的我,我只能检查
。投票结束。
I am having some issues finding a decent tutorial for generating a loading style screen with regards to HTML5. To be quite honest I'm not sure exactly where to begin...
My project is essentially a simple HTML5 game, where I'll be loading in various sprite sheets and tilesets. They'll be reasonably small, but I'd like to show a little loading spinner instead of a blank screen while all the resources are loaded.
Much appreciated if somebody could point me in the right direction, be it decent links or code samples to get me going...my Google-fu is lacking today!
For clarification, I need to figure out how to load the resources themselves, as opposed to finding a spinner. For instance, how to calculate that X% has loaded.
Edit 2
Silly me, I can just check for <variable>.image.complete
. Voted to close.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这个网站非常适合动画加载 gif:http://ajaxload.info/。覆盖层可用于显示图像,并防止在加载页面时与页面交互。您可以使用 div,将其放置在其他所有内容之上 (
z-index
),并将宽度和高度设置为100%
。This website is excellent for animated loading gifs: http://ajaxload.info/. An overlay can be used to display the image and also prevent interaction with the page while it is loading. You can use a div, position it above everything else (
z-index
) and set the width and height to100%
.这是一个老问题,但了解 Image 对象也有一个 onload 事件很有用。使用它通常比在循环中检查完整要好得多。
示例用法(未实际检查是否有效):
An old question, but it is usefull to know that the Image object also has an onload event. It is often way better to use that than check for complete in for example a loop.
Example usage (not actually checked if working):
这是演示 HTML5 CSS 动画的优秀资源。
http://slides.html5rocks.com/#css-animation
这演示了如何创建加载状态栏:
http://slides.html5rocks.com/#semantic-tags-2
有这些幻灯片上还有很多其他示例,可能有您正在寻找的内容。
This is an excellent resource for demonstrating HTML5 CSS animation.
http://slides.html5rocks.com/#css-animation
This demonstrates how to create a loading status bar:
http://slides.html5rocks.com/#semantic-tags-2
There are plenty of other examples on those slides as well that may have what you're looking for.
您可以在 HTML5 中使用
元素。请参阅此页面以获取源代码和现场演示。
http://purpledesign.in/blog/super-cool-loading-bar- html5/
这里是进度元素...
这将具有从 20 开始的加载值。当然,只有该元素是不够的。您需要在脚本加载时移动它。为此我们需要 JQuery。这是一个简单的 JQuery 脚本,它从 0 开始进度到 100,并在定义的时间段内执行某些操作。
将其添加到您的 HTML 文件中。
希望这会给您一个开始。
You can use
<progress>
element in HTML5. See this page for source code and live demo.http://purpledesign.in/blog/super-cool-loading-bar-html5/
here is the progress element...
this will have the loading value starting from 20. Of course only the element wont suffice. You need to move it as the script loads. For that we need JQuery. Here is a simple JQuery script that starts the progress from 0 to 100 and does something in defined time slot.
Add this to your HTML file.
Hope this will give you a start.
因为这个问题被标记为 html5 - 我认为我们可以比 spinner gif 做得更好。更现代的替代方案:
http://fgnass.github.io/spin.js/
Because this question is tagged with html5 - I think we can do better than a spinner gif. A more modern alternative:
http://fgnass.github.io/spin.js/