在响应图像jquery大小调整器上将最大大小设置为本机图像大小

在响应图像jquery大小调整器上将最大大小设置为本机图像大小,jquery,responsive-design,Jquery,Responsive Design,预先警告:我是一个主要的新手 我使用的这段代码可以根据浏览器窗口的大小调整网站上图像的大小。问题是,图像也被放大到超过其原始大小,从而产生丑陋的像素图像。我想知道: 有一种方法可以添加一些代码,以防止图像放大超过其原始上传大小 任何帮助都将不胜感激 以下是我目前拥有的: (function( $ ) { $.fn.aeImageResize = function( params ) { var aspectRatio = 0 // Nasty I know but it's done onl

预先警告:我是一个主要的新手

我使用的这段代码可以根据浏览器窗口的大小调整网站上图像的大小。问题是,图像也被放大到超过其原始大小,从而产生丑陋的像素图像。我想知道:

有一种方法可以添加一些代码,以防止图像放大超过其原始上传大小

任何帮助都将不胜感激

以下是我目前拥有的:

(function( $ ) {

$.fn.aeImageResize = function( params ) {

var aspectRatio = 0
// Nasty I know but it's done only once, so not too bad I guess
// Alternate suggestions welcome :)
,   isIE6 = $.browser.msie && (6 == ~~ $.browser.version)
;

// We cannot do much unless we have one of these
if ( !params.height && !params.width ) {
return this;
}

// Calculate aspect ratio now, if possible
if ( params.height && params.width ) {
aspectRatio = params.width / params.height;
}

// Attach handler to load
// Handler is executed just once per element
// Load event required for Webkit browsers
return this.one( "load", function() {

// Remove all attributes and CSS rules
this.removeAttribute( "height" );

this.style.height = "";

var imgHeight = this.height
, imgWidth = this.width
, imgAspectRatio = imgWidth / imgHeight
, bxHeight = params.height
, bxWidth = params.width
, bxAspectRatio = aspectRatio;

// Work the magic!
// If one parameter is missing, we just force calculate it
if ( !bxAspectRatio ) {
if ( bxHeight ) {
bxAspectRatio = imgAspectRatio + 1;
} else {
bxAspectRatio = imgAspectRatio - 1;
}
}

// Only resize the images that need resizing


if ( imgAspectRatio > bxAspectRatio ) {
bxHeight = ~~ ( imgHeight / imgWidth * bxWidth );
} else {
bxWidth = ~~ ( imgWidth / imgHeight * bxHeight );
}

this.height = bxHeight-100;

})
.each(function() {

// Trigger load event (for Gecko and MSIE)
if ( this.complete || isIE6 ) {
$( this ).trigger( "load" );
}
});
};
})( jQuery );

请在函数开头尝试以下操作:

if (params.height < this.height ||
    params.width < this.width)
{
  return this;
}