jQuery - Wait till background images have loaded then show element

♀尐吖头ヾ 提交于 2019-11-28 12:35:57

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.
    }
});
entropo

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:

Also, an SO q/a that might be helpful: Preloading images with jQuery

I can confirm that the 'ImagesLoaded' Plugin works for me.

Use like so:

// jQuery
$('#container').imagesLoaded( { background: true }, function() {
  console.log('#container background image loaded');
});

// vanilla JS
imagesLoaded( '#container', { background: true }, function() {
  console.log('#container background image loaded');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!