// Nice job
$('#app img').one('load', function() {
const height = $(this).height();
const width = $(this).width();
$(this).css({
height: height / 100 + 'rem',
width: width / 100 + 'rem',
});
})
.each(function() {
if(this.complete) $(this).load();
});
532down voteaccepted
If the src
is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete
, like this:
$("img").one("load", function() {
// do stuff
}).each(function() {
if(this.complete) $(this).load();
});