//***控制图片比例*********//
// HuTao_oImg : 图片对像 //
// maxWidth : 最大宽度 //
// maxHeight : 最大高度 //
// 调用方法 : <img src="**.jpg" οnlοad="HuTao_DrawImage(this,120,80)">
function HuTao_DrawImage(HuTao_oImg,maxWidth,maxHeight)
{
var initialWidth = HuTao_oImg.width;
var initialHeight = HuTao_oImg.height;
var goalWidth = initialWidth;
var goalHeight = initialHeight;
if (initialWidth > maxWidth || initialHeight > maxHeight) {
if (initialWidth / maxWidth >= initialHeight / maxHeight) {
var goalWidth = maxWidth;
var goalHeight = (initialHeight * maxWidth) / initialWidth;
}
else {
var goalWidth = (initialWidth * maxHeight) / initialHeight;
var goalHeight = maxHeight;
}
}
else if (initialWidth < maxWidth && initialHeight < maxHeight) {
if (initialWidth / maxWidth >= initialHeight / maxHeight) {
var goalWidth = maxWidth;
var goalHeight = (initialHeight * maxWidth) / initialWidth;
}
else {
var goalWidth = (initialWidth * maxHeight) / initialHeight;
var goalHeight = maxHeight;
}
}
HuTao_oImg.width = goalWidth;
HuTao_oImg.height = goalHeight;
}