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

前端 未结 14 1406
轻奢々
轻奢々 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:16

    Do you really have to do it with jQuery? You can attach the onload event directly to your image as well;

    
    

    It will fire every time the image has loaded, from cache or not.

提交回复
热议问题