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

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

    I had this problem with IE where the e.target.width would be undefined. The load event would fire but I couldn't get the dimensions of the image in IE (chrome + FF worked).

    Turns out you need to look for e.currentTarget.naturalWidth & e.currentTarget.naturalHeight.

    Once again, IE does things it's own (more complicated) way.

提交回复
热议问题