diff --git a/src/js/items-controller.js b/src/js/items-controller.js index 6993f5e57..8f7a35522 100644 --- a/src/js/items-controller.js +++ b/src/js/items-controller.js @@ -197,6 +197,19 @@ var _getItemAt, var w = maxRes ? item.w : Math.round(item.w * item.fitRatio), h = maxRes ? item.h : Math.round(item.h * item.fitRatio); + // ensure correct aspect ratio + if(img.naturalHeight && img.naturalWidth) { + var new_h = w * (img.naturalHeight / img.naturalWidth); + if(new_h > h) { + var new_w = h * (img.naturalWidth / img.naturalHeight); + img.style.marginLeft = (w - new_w) / 2 + 'px'; + w = new_w; + } else { + img.style.marginTop = (h - new_h) / 2 + 'px'; + h = new_h; + } + } + if(item.placeholder && !item.loaded) { item.placeholder.style.width = w + 'px'; item.placeholder.style.height = h + 'px'; @@ -490,4 +503,4 @@ _registerModule('Controller', { } } -}); \ No newline at end of file +});