简体   繁体   English

使用jQuery检测引导程序加载的图像

[英]Detect images loaded in bootstrap modal with jQuery

I have a button on my page for open bootstrap modal with thousands of images in unordered list like this: ul > li.thumbnail > img.image . 我的页面上有一个按钮,用于打开引导程序模态,其中包含成千上万个未排序列表中的图像,例如: ul > li.thumbnail > img.image I need to show a fullscreen loader after modal is opened and hide loader after images are loaded. 打开模态后,我需要显示一个全屏加载程序,并在加载图像后隐藏加载程序。 But there is not strict count of li elements. 但是对li元素的计数并不严格。 Do you have any idea how can I do this? 你知道我该怎么做吗? Thank you! 谢谢!

//EDIT //编辑

but I dont need to load it on full page load, I want to load it on modal open 但是我不需要在全页加载中加载它,我想在模式打开时加载它

I have a possible solution 我有可能的解决方案

var loader = $('#loading'); //fullscreen loading animation
$("#lg-modal").on('show.bs.modal', function (e) {
        loader.css({ 'display': 'block' });
        $(window).load(function () {
            loader.css({ 'display': 'none' });
        });
    });

It works correctly (I need some more tests) for now. 现在它可以正常工作(我需要更多测试)。 Do you have any ideas or better way for this? 您对此有任何想法或更好的方法吗? Thanks! 谢谢!

EDIT: this is not correct solution, because when modal is loaded, and I show loaded modal, page is not loading any content.. 编辑:这不是正确的解决方案,因为加载模式时,并且显示加载的模式时,页面未加载任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM