clacImgZoomParam方法源码

function clacImgZoomParam( maxWidth, maxHeight, width, height ){  //传入四个参数:最大宽度,最大高度,宽度,高度;
var param = { width, height:height, top:0, left:0 };

if( width>maxWidth || height>maxHeight ){
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;

if( rateWidth > rateHeight ){
param.width = maxWidth;
param.height = height / rateWidth;
}else{
param.width = width / rateHeight;
param.height = maxHeight;
}
}

param.left = (maxWidth - param.width) / 2;
param.top = (maxHeight - param.height) / 2;

return param;
}
通过这个方法可以很好的判断图片的大小,并以适合的宽高显示在页面中
原文地址:https://www.cnblogs.com/webwangjie/p/7092987.html