function thumbImg(_img, _width, _height) {
var imgWidth = $(_img).width();
var imgHeight = $(_img).height();
if (imgWidth > _width || imgHeight > _height) {
if ((_width /_height) >= (imgWidth / imgHeight)) {
$(_img).width((_height * imgWidth) / imgHeight);
$(_img).height(_height);
}
else {
$(_img).width(_width);
$(_img).height((_width * imgHeight) / imgWidth);
}
}
}
var imgWidth = $(_img).width();
var imgHeight = $(_img).height();
if (imgWidth > _width || imgHeight > _height) {
if ((_width /_height) >= (imgWidth / imgHeight)) {
$(_img).width((_height * imgWidth) / imgHeight);
$(_img).height(_height);
}
else {
$(_img).width(_width);
$(_img).height((_width * imgHeight) / imgWidth);
}
}
}
本文介绍了一个用于调整图像尺寸的函数,通过计算保持原始宽高比的方式,确保图像缩放不失真。
9822

被折叠的 条评论
为什么被折叠?



