jQuery callback on image load (even when the image is cached)

前端 未结 14 1174
轻奢々
轻奢々 2020-11-21 06:25

I want to do:

$(\"img\").bind(\'load\', function() {
  // do stuff
});

But the load event doesn\'t fire when the image is loaded from cache

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-21 07:19

    You can solve your problem using JAIL plugin that also allows you to lazy load images (improving the page performance) and passing the callback as parameter

    $('img').asynchImageLoader({callback : function(){...}});
    

    The HTML should look like

    
    

提交回复
热议问题