jQuery - 等到背景图像加载然后显示元素 [英] jQuery - Wait till background images have loaded then show element

查看:26
本文介绍了jQuery - 等到背景图像加载然后显示元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

解决方案

My plugin, waitForImages, allows you to attach callbacks when images have loaded.

It supports images referenced in the CSS.

$('#some-container').waitForImages({
    waitForAll: true,
    finished: function() {
        // Loaded all images referenced in CSS.
    }
});

这篇关于jQuery - 等到背景图像加载然后显示元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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