Wait for images to load and then execute all other code

后端 未结 6 1669
广开言路
广开言路 2021-02-14 14:24

OK, I\'m losing my mind over this. I did read here at SO and google about it, I even have the preloader set (found here on SO), but none of the plugins/code I found helped me. <

6条回答
  •  春和景丽
    2021-02-14 14:58

    I have a plugin named waitForImages that lets you attach a callback when descendent images have loaded.

    In your case, if you wanted to wait for all assets to download, $(window).load() may be fine. But you could do it a bit cooler with my plugin :)

    var loading = $('#loading');
    
    $('body').waitForImages(function()
    {    
        loading.addClass('hidden');  
    }, function(loaded, total)
    {
        loading.html(loaded + ' of ' + total);
    
    });
    

提交回复
热议问题