jQuery - 等待背景图像加载然后显示元素
我确实找到了一些地方,告诉他们如何执行此操作,但它要么超级不方便,要么根本不起作用..(这些人自己的示例不起作用..)
基本上我有背景图像,我想在同时而不是让它们在需要时加载到文档中...
我不一定需要首先加载它们或任何东西而是要等到特定的背景图像加载然后显示它们的父div..
那样,那会有很大的不同
另外,如果可能的话......如果这些背景图像可以定义为通过类加载而不是指定实际的图像名称......就像.load-bg ~ background load ~ show element
。我是要到达月球还是这是可行的?
I did find a few places where it was told how to do this but it was either super inconvenient or just didnt work.. ( the guys own example did not work.. )
Basically i have background images that i would like to show at the same time instead of letting them to load in to the document when ever they please...
I dont necessarily need them to be loaded first or anything but to wait until specific background images load up and then show their parent div..
Also if its possible.. it would make big difference if those background images could be defined to be loaded through classes rather than specifying the actual image name... like
.load-bg ~ background load ~ show element..
Am i reaching for the moon or is this doable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的插件 waitForImages 允许您在加载图像时附加回调。
它支持 CSS 中引用的图像。
My plugin, waitForImages, allows you to attach callbacks when images have loaded.
It supports images referenced in the CSS.
您可以使用异步图像加载器,并回调显示保存图像的 div 的事件。以下是一些异步加载器:
allcomplete
事件。另外,一个可能有用的问题解答:使用 jQuery 预加载图像
You could use an asynchronous image loader with a callback to an event which shows the divs holding the images. Here are some async loaders:
allcomplete
event on that page.Also, an SO q/a that might be helpful: Preloading images with jQuery
我可以确认“ImagesLoaded”插件适合我。
像这样使用:
I can confirm that the 'ImagesLoaded' Plugin works for me.
Use like so: