Wait for images to load and then execute all other code

后端 未结 6 1656
广开言路
广开言路 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:57

    The waitForImages pluggin is an interesting one, but the solution can be achieved just with:

        var counter = 0;
        var size = $('img').length;
    
        $("img").load(function() { // many or just one image(w) inside body or any other container
            counter += 1;
            counter === size && $('body').css('background-color', '#fffaaa');
        }).each(function() {
          this.complete && $(this).load();        
        });
    

提交回复
热议问题