`

Jquery控制图片宽度及高度 ,做到等比例缩放

 
阅读更多

 

$(document).ready(function() {
		    var maxWidth = 780;
		    var maxHeight = 500;
		    var zoomTimes;
		    $("img").each(function(){			
				    var curWidth  = $(this).width();
				    var curHeight = $(this).height();
				    if(curWidth > maxWidth){
				         $(this).width(maxWidth);
				         zoomTimes=curWidth/maxWidth;
				         $(this).height(curHeight/zoomTimes);
				    }else if(curHeight > maxHeight){
				         $(this).height(maxHeight);
				         zoomTimes=curHeight/maxHeight;
				         $(this).width(curWidth/zoomTimes);
				    }
			    });
		});
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics