【发布时间】:2014-06-13 17:04:46
【问题描述】:
我希望能够显示一个宽度适合浏览器屏幕的图像,高度根据纵横比调整大小,并且图像不会变得比他的原始大小大。 我找到了this post,第一个答案中提供的链接有点像我想要的,但不完全是。它调整图像大小而不限制最大尺寸。我该怎么做?
答案中的代码:
(function ($) {
$.fn.photoResize = function (options) {
var element = $(this),
defaults = {
bottomSpacing: 10
};
$(element).load(function () {
updatePhotoHeight();
$(window).bind('resize', function () {
updatePhotoHeight();
});
});
options = $.extend(defaults, options);
function updatePhotoHeight() {
var o = options,
photoHeight = $(window).height();
$(element).attr('height', photoHeight - o.bottomSpacing);
}
};
}(jQuery));
【问题讨论】:
-
请检查我的答案(目前被否决),我修改了原始插件以考虑不放大图像。