我的图片尺寸为alfa
x beta
像素。
然后onDocumentReady
和onWindowResize
我计算当前的文档尺寸。
任务是按比例缩放图像,直到达到其中一个尺寸。
答案 0 :(得分:2)
$(document).ready(function() {
scaleStart();
});
$(window).resize(function() {
scaleStart();
});
function scaleStart() {
$("#myImage").css("min-width", 0);
$("#myImage").css("min-height", 0);
var originalWidth = 1762;
var originalHeight = 1041;
var safeWidth = $(document).width() - 100;
var safeHeight = $(document).height() - 100;
var scaleWidth = originalWidth / safeWidth;
var scaleHeight = originalHeight / safeHeight;
if (scaleWidth > scaleHeight)
{
$("#myImage").css("min-width", originalWidth / scaleWidth);
$("#myImage").css("min-height", originalHeight / scaleWidth);
}
else
{
$("#myImage").css("min-width", originalWidth / scaleHeight);
$("#myImage").css("min-height", originalHeight / scaleHeight);
}
}