jQuery event for images loaded

后端 未结 14 1202
离开以前
离开以前 2020-11-22 15:25

Is it possible to detect when all images are loaded via a jQuery event?

Ideally, there should be a

$(document).idle(function()
{
}

14条回答
  •  伪装坚强ぢ
    2020-11-22 15:50

    imagesLoaded Plugin is way to go ,if you need a crossbrowser solution

     $("", {src: 'image.jpg'}).imagesLoaded( function( $images, $proper, $broken ){
     if($broken.length > 0){
     //Error CallBack
     console.log('Error');
     }
     else{
     // Load CallBack
     console.log('Load');
     }
     });
    

    If You Just Need a IE WorkAround,This Will Do

     var img = $("", {
        error: function() {console.log('error'); },
        load: function() {console.log('load');}
        });
      img.attr('src','image.jpg');
    

提交回复
热议问题