Skip to content

Commit 144be31

Browse files
committed
Merge pull request #132 from jeremija/image-width-fix
Fixed bug where image width changes on refresh
2 parents 72ba094 + a149b03 commit 144be31

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)