jQuery超出父div宽度自动按比例缩小

<script>var adjustImgSize = function(img, boxWidth) {
var tempImg = new Image();
tempImg.src = img.attr(‘src’);
var imgWidth=tempImg.width;
var imgHeight=tempImg.height;

if(imgWidth > boxWidth)
{
img.width(boxWidth);
img.height((boxWidth*imgHeight)/imgWidth);

}
};

$(function() {
$(‘.content-1 img’).load(function() {
adjustImgSize($(this), $(this).parent().width());
});
});</script>

点赞