function scaleImage(ImgD, FitWidth, FitHeight){
var width = ImgD.width, height = ImgD.height;
var w = width / FitWidth, h = height / FitHeight;
if (w >= h) { //宽度固定,高度缩放
ImgD.width = FitWidth;
ImgD.height= height / w;
jQuery(ImgD).css("margin-top", (FitHeight-ImgD.height) / 2);
//垂直居中
} else { //高度固定,宽度缩放
ImgD.height= FitHeight;
ImgD.width = width / h;
}
};
文章图片