﻿//按比例缩放图片 
function setImg(ImgD,proMaxWidth,proMaxHeight){
var image=new Image(); 
image.src=ImgD.src;

if(image.width>0 && image.height>0){ 
   var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
  
   if(rate <= 1){   
    ImgD.style.width = image.width*rate;
    ImgD.style.height =image.height*rate;
    //垂直居中
    ImgD.style.marginTop=((proMaxHeight-image.height*rate)/2)+"px";
    ImgD.style.marginBottom=((proMaxHeight-image.height*rate)/2)+"px";
   
   }
   else {
    ImgD.style.width = image.width;
    ImgD.style.height =image.height;
    //垂直居中
    ImgD.style.marginTop=((proMaxHeight-image.height)/2)+"px";
    ImgD.style.marginBottom=((proMaxHeight-image.height)/2)+"px";
   }
}
}
