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

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

    By using jQuery to generate a new image with the image's src, and assigning the load method directly to that, the load method is successfully called when jQuery finishes generating the new image. This is working for me in IE 8, 9 and 10

    $('', {
        "src": $("#img").attr("src")
    }).load(function(){
        // Do something
    });
    

提交回复
热议问题