mirror of https://github.com/ElemeFE/element
fix: fix incorrect image object fit ratio in IE (#19583)
parent
18cf34f7b5
commit
493e18877a
|
@ -204,7 +204,8 @@
|
||||||
|
|
||||||
if (!imageWidth || !imageHeight || !containerWidth || !containerHeight) return {};
|
if (!imageWidth || !imageHeight || !containerWidth || !containerHeight) return {};
|
||||||
|
|
||||||
const vertical = imageWidth / imageHeight < 1;
|
const imageAspectRatio = imageWidth / imageHeight;
|
||||||
|
const containerAspectRatio = containerWidth / containerHeight;
|
||||||
|
|
||||||
if (fit === ObjectFit.SCALE_DOWN) {
|
if (fit === ObjectFit.SCALE_DOWN) {
|
||||||
const isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
|
const isSmaller = imageWidth < containerWidth && imageHeight < containerHeight;
|
||||||
|
@ -215,9 +216,9 @@
|
||||||
case ObjectFit.NONE:
|
case ObjectFit.NONE:
|
||||||
return { width: 'auto', height: 'auto' };
|
return { width: 'auto', height: 'auto' };
|
||||||
case ObjectFit.CONTAIN:
|
case ObjectFit.CONTAIN:
|
||||||
return vertical ? { width: 'auto' } : { height: 'auto' };
|
return (imageAspectRatio < containerAspectRatio) ? { width: 'auto' } : { height: 'auto' };
|
||||||
case ObjectFit.COVER:
|
case ObjectFit.COVER:
|
||||||
return vertical ? { height: 'auto' } : { width: 'auto' };
|
return (imageAspectRatio < containerAspectRatio) ? { height: 'auto' } : { width: 'auto' };
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue