私は、特定の四角形内で画像のアスペクト比を維持しながら絶対最大サイズを決定するために使用している関数を持っています。私が現在使っているコードは間違っていますが、どこが間違っているのか分かりません。画像が四角形内に収まる最大サイズの決定
// Sets the image to the largest proportional size possible
// based on the current browser window dimensions and original
// image size specified by the image loader
function applyLargestProportionalSize() {
var maxWidth = <width of container>;
var maxHeight = <height of container>;
var realWidth = <actual image width>;
var realHeight = <actual image height>;
if (realWidth < realHeight && maxWidth > maxHeight) {
var scaledWidth = Math.min(realWidth, maxWidth);
$('img').css('width', scaledWidth);
// let height be determined by the browser
} else {
var scaledHeight = Math.min(realHeight, maxHeight);
$('img').css('height', scaledHeight);
// let width be determined by the browser
}
}
コードが間違っていることをどのように知っていますか?どうしたの? –