如何编写 Javascript 预加载器?
我不是在谈论如何使用Javascript预加载图像,我更多地考虑了 Flash 预加载器的思路,它在 SWF 加载时显示某种反馈。
该网站大量使用 Javascript,并且在页面加载时需要许多大图像,因此我希望将该网站隐藏在加载屏幕后面,直到初始图像全部加载。
I'm not talking about how to pre-load images using Javascript, I am thinking more along the lines of a Flash preloader which displays some sort of feedback while the SWF loads.
The site in question has heavy Javascript usage and requires many large images at page load so I wish to hide the site behind a loading screen till the initial images are all loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我编写了一个名为 waitForImages 的 jQuery 插件,它可以让你做到这一点。
回调允许您在加载每个图像时执行任何操作...
jsFiddle。
I wrote a jQuery plugin called waitForImages that lets you do this.
The callbacks allow you to do whatever when each image has loaded...
jsFiddle.
我第一次学习 JavaScript 时写过一篇。我稍后会尝试找到它。基本思想是在页面外部有一个隐藏元素,并在其中加载图像。
当心,丑陋的代码是我一开始写的。此外,尽管有很好的评论,但它可能并不完全是您想要的。只需修改它并使其成为通用函数即可。基于 jQuery,用于 javascript 画廊:
I have one written when I first learned JavaScript. I'm going to try to find it in a second. The basic idea is to have a hidden element that's outside the page, and load your image in there.
Beware, ugly code as I wrote this when i started. Also it probably is not exactly what you're looking for, though there are good comments. Just modify it and make it a generic function. Based on jQuery, for a javascript gallery: