简体   繁体   中英

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 . 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. 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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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