Skip to content

Commit

Permalink
Image smaller than the container should not be upscaled when "fill" i…
Browse files Browse the repository at this point in the history
…s set to false
  • Loading branch information
GuruParin committed Feb 24, 2017
1 parent 2409266 commit c28b326
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions js/imgLiquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ imgLiquid.injectCss = '.imgLiquid img {visibility:hidden}';
}

$imgBoxCont.css({
'background-size': (settings.fill) ? 'cover' : 'contain',
'background-size': (!settings.fill && $img[0].width <= $imgBoxCont.width() && $img[0].height <= $imgBoxCont.height()) ? 'auto' : (settings.fill) ? 'cover' : 'contain',
'background-position': (settings.horizontalAlign + ' ' + settings.verticalAlign).toLowerCase(),
'background-repeat': 'no-repeat'
});
Expand Down Expand Up @@ -325,16 +325,23 @@ imgLiquid.injectCss = '.imgLiquid img {visibility:hidden}';


// Compare ratio
if (settings.fill === ($imgCW / $imgCH) >= ($img.data('owidth') / $img.data('oheight'))) {
w = '100%';
if (!settings.fill && $img.data('owidth') <= $imgCW && $img.data('oheight') <= $imgCH) {
w = 'auto';
h = 'auto';
wn = Math.floor($imgCW);
hn = Math.floor($imgCW * ($img.data('oheight') / $img.data('owidth')));
wn = $img.data('owidth');
hn = $img.data('oheight');
} else {
w = 'auto';
h = '100%';
wn = Math.floor($imgCH * ($img.data('owidth') / $img.data('oheight')));
hn = Math.floor($imgCH);
if (settings.fill === ($imgCW / $imgCH) >= ($img.data('owidth') / $img.data('oheight'))) {
w = '100%';
h = 'auto';
wn = Math.floor($imgCW);
hn = Math.floor($imgCW * ($img.data('oheight') / $img.data('owidth')));
} else {
w = 'auto';
h = '100%';
wn = Math.floor($imgCH * ($img.data('owidth') / $img.data('oheight')));
hn = Math.floor($imgCH);
}
}

// Align X
Expand Down

0 comments on commit c28b326

Please sign in to comment.