javascripthtmlcssimageactionscript-2

Resizing different type of image


I'm searching a JavaScript method to resize and fill in a block with a fixed width some different images with different types of width and height.

I've found actually something looking familiar but it's in AS2 I don't know if it can be conversed in JavaScript.

var _loc3 = _caseWidth * 100 / caseItem.item._width;
var _loc2 = _caseHeight * 100 / caseItem.item._height;
caseItem._xscale = caseItem._yscale = _loc3 > _loc2 ? (_loc2) : (_loc3);
caseItem.item._x = -caseItem.item.getBounds(caseItem).xMin + (_caseWidth - caseItem._width) / 2;
caseItem.item._y = -caseItem.item.getBounds(caseItem).yMin;

Solution

  • I think it's easier to use object-fit: cover with CSS. You will avoid unnecessary javascript loads