js图片等比例缩放

<SCRIPT LANGUAGE="JavaScript">
<!--
//图片等比例缩放
 
var FitWidth = 170; //图片宽度
var FitHeight = 150; //图片高度
function ResizePic(ImgTag)
{
var image = new Image();
image.src = ImgTag.src;
if(image.width>0 && image.height>0){
if(image.width/image.height >= FitWidth/FitHeight){
if(image.width > FitWidth){
ImgTag.width = FitWidth;
ImgTag.height = (image.height*FitWidth)/image.width;
}
else{
ImgTag.width = image.width;
ImgTag.height = image.height;
}
}
else{
if(image.height > FitHeight){
ImgTag.height = FitHeight;
ImgTag.width = (image.width*FitHeight)/image.height;
}
else{
ImgTag.width = image.width;
ImgTag.height = image.height;
}
}
}
}
-->


© 2016-2021 阿尔佛 aerfo.com | 豫ICP备17044542号 | 豫公网安备 41010602000172