Skip to content

Commit 493e188

Browse files
authored
fix: fix incorrect image object fit ratio in IE (#19583)
1 parent 18cf34f commit 493e188

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/image/src/main.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@
204204
205205
if (!imageWidth || !imageHeight || !containerWidth || !containerHeight) return {};
206206
207-
const vertical = imageWidth / imageHeight < 1;
207+
const imageAspectRatio = imageWidth / imageHeight;
208+
const containerAspectRatio = containerWidth / containerHeight;
208209
209210
if (fit === ObjectFit.SCALE_DOWN) {
210211
const isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
@@ -215,9 +216,9 @@
215216
case ObjectFit.NONE:
216217
return { width: 'auto', height: 'auto' };
217218
case ObjectFit.CONTAIN:
218-
return vertical ? { width: 'auto' } : { height: 'auto' };
219+
return (imageAspectRatio < containerAspectRatio) ? { width: 'auto' } : { height: 'auto' };
219220
case ObjectFit.COVER:
220-
return vertical ? { height: 'auto' } : { width: 'auto' };
221+
return (imageAspectRatio < containerAspectRatio) ? { height: 'auto' } : { width: 'auto' };
221222
default:
222223
return {};
223224
}

0 commit comments

Comments
 (0)