Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit 02c5d3d

Browse files
charlie0228CarterLi
authored andcommitted
fix: fix incorrect image object fit ratio in IE (ElemeFE#19583)
1 parent e235b1e commit 02c5d3d

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
@@ -212,7 +212,8 @@
212212
213213
if (!imageWidth || !imageHeight || !containerWidth || !containerHeight) return {};
214214
215-
const vertical = imageWidth / imageHeight < 1;
215+
const imageAspectRatio = imageWidth / imageHeight;
216+
const containerAspectRatio = containerWidth / containerHeight;
216217
217218
if (fit === ObjectFit.SCALE_DOWN) {
218219
const isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
@@ -223,9 +224,9 @@
223224
case ObjectFit.NONE:
224225
return { width: 'auto', height: 'auto' };
225226
case ObjectFit.CONTAIN:
226-
return vertical ? { width: 'auto' } : { height: 'auto' };
227+
return (imageAspectRatio < containerAspectRatio) ? { width: 'auto' } : { height: 'auto' };
227228
case ObjectFit.COVER:
228-
return vertical ? { height: 'auto' } : { width: 'auto' };
229+
return (imageAspectRatio < containerAspectRatio) ? { height: 'auto' } : { width: 'auto' };
229230
default:
230231
return {};
231232
}

0 commit comments

Comments
 (0)