$(function () {
var imgs = $('a>img');
imgs.each(function () {
var img = $(this);
var width = img.attr('width');//area width
var height = img.attr('height');//Region height
var showWidth = width;//Final display width
var showHeight = height;//Final display height
var ratio = width / height;//Aspect ratio
img.load(function () {
var imgWidth, imgHeight, imgratio;
$('
').attr('src ', img.attr('src')).load(function () {
imgWidth = this.width;//The actual width of the picture
imgHeight = this.height;//The actual height of the picture
imgRatio = imgWidth / imgHeight;//Actual aspect ratio
if (ratio > imgRatio) {
showWidth = height * imgRatio;//Adjusted width is too small
img.attr('width', showWidth) .css('margin-left', (width - showWidth) / 2);
.attr('height', showHeight).css('margin-top', (height - showHeight) / 2);
. >
In this way, the image is enlarged and reduced in equal proportions.