Skip to content

Commit

Permalink
fix: fix incorrect image object fit ratio in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie0228 committed Jun 6, 2020
1 parent bf534d9 commit f223b9b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/image/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {};
}
Expand Down

0 comments on commit f223b9b

Please sign in to comment.