Skip to content

Commit a149b03

Browse files
committed
Fixes variable image width bug
closes #95 - added onload event listeners to images
1 parent 72ba094 commit a149b03

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

assets/js/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,22 @@
3737
var $postContent = $(".post-content");
3838
$postContent.fitVids();
3939

40-
var casperFullImg = function () {
41-
$("img").each(function () {
42-
var $this = $(this),
43-
contentWidth = $postContent.outerWidth(), // Width of the content
44-
imageWidth = $this[0].naturalWidth; // Original image resolution
45-
46-
if (imageWidth >= contentWidth) {
47-
$this.addClass('full-img');
48-
} else {
49-
$this.removeClass('full-img');
50-
}
51-
});
52-
};
40+
function updateImageWidth() {
41+
var $this = $(this),
42+
contentWidth = $postContent.outerWidth(), // Width of the content
43+
imageWidth = this.naturalWidth; // Original image resolution
44+
45+
if (imageWidth >= contentWidth) {
46+
$this.addClass('full-img');
47+
} else {
48+
$this.removeClass('full-img');
49+
}
50+
}
51+
52+
var $img = $("img").on('load', updateImageWidth);
53+
function casperFullImg() {
54+
$img.each(updateImageWidth);
55+
}
5356

5457
casperFullImg();
5558
$(window).smartresize(casperFullImg);

0 commit comments

Comments
 (0)