From f223b9b9beef94793f58c2e1ee9a1436705fcfec Mon Sep 17 00:00:00 2001 From: AzureBlue Date: Sat, 6 Jun 2020 23:44:11 +0800 Subject: [PATCH] fix: fix incorrect image object fit ratio in IE --- packages/image/src/main.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/image/src/main.vue b/packages/image/src/main.vue index 0cad4e0accb..5598bde8a27 100644 --- a/packages/image/src/main.vue +++ b/packages/image/src/main.vue @@ -204,7 +204,8 @@ if (!imageWidth || !imageHeight || !containerWidth || !containerHeight) return {}; - const vertical = imageWidth / imageHeight < 1; + const imageAspectRatio = imageWidth / imageHeight; + const containerAspectRatio = containerWidth / containerHeight; if (fit === ObjectFit.SCALE_DOWN) { const isSmaller = imageWidth < containerWidth && imageHeight < containerHeight; @@ -215,9 +216,9 @@ case ObjectFit.NONE: return { width: 'auto', height: 'auto' }; case ObjectFit.CONTAIN: - return vertical ? { width: 'auto' } : { height: 'auto' }; + return (imageAspectRatio < containerAspectRatio) ? { width: 'auto' } : { height: 'auto' }; case ObjectFit.COVER: - return vertical ? { height: 'auto' } : { width: 'auto' }; + return (imageAspectRatio < containerAspectRatio) ? { height: 'auto' } : { width: 'auto' }; default: return {}; }