Skip to content

Commit a01ab69

Browse files
committed
fix: use max[Width|Height] when fitImagesInViewport is false
1 parent dff822e commit a01ab69

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/js/lightbox.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,24 @@
327327
maxImageHeight = self.options.maxHeight;
328328
}
329329

330-
// Is the current image's width or height is greater than the maxImageWidth or maxImageHeight
331-
// option than we need to size down while maintaining the aspect ratio.
332-
if ((preloader.width > maxImageWidth) || (preloader.height > maxImageHeight)) {
333-
if ((preloader.width / maxImageWidth) > (preloader.height / maxImageHeight)) {
334-
imageWidth = maxImageWidth;
335-
imageHeight = parseInt(preloader.height / (preloader.width / imageWidth), 10);
336-
$image.width(imageWidth);
337-
$image.height(imageHeight);
338-
} else {
339-
imageHeight = maxImageHeight;
340-
imageWidth = parseInt(preloader.width / (preloader.height / imageHeight), 10);
341-
$image.width(imageWidth);
342-
$image.height(imageHeight);
343-
}
330+
} else {
331+
maxImageWidth = self.options.maxWidth || preloader.width || maxImageWidth;
332+
maxImageHeight = self.options.maxHeight || preloader.height || maxImageHeight;
333+
}
334+
335+
// Is the current image's width or height is greater than the maxImageWidth or maxImageHeight
336+
// option than we need to size down while maintaining the aspect ratio.
337+
if ((preloader.width > maxImageWidth) || (preloader.height > maxImageHeight)) {
338+
if ((preloader.width / maxImageWidth) > (preloader.height / maxImageHeight)) {
339+
imageWidth = maxImageWidth;
340+
imageHeight = parseInt(preloader.height / (preloader.width / imageWidth), 10);
341+
$image.width(imageWidth);
342+
$image.height(imageHeight);
343+
} else {
344+
imageHeight = maxImageHeight;
345+
imageWidth = parseInt(preloader.width / (preloader.height / imageHeight), 10);
346+
$image.width(imageWidth);
347+
$image.height(imageHeight);
344348
}
345349
}
346350
self.sizeContainer($image.width(), $image.height());

0 commit comments

Comments
 (0)