我正在研究一些jQuery来调整页面上的图像大小。此块工作正常:为什么这总是评估错误?
var size = 350;
$("img").each(function() {
if ($(this).height() > $(this).width()) {
var h = size;
var w = Math.ceil(($(this).width()/$(this).height()) * size);
}
else {
var w = size;
var h = Math.ceil(($(this).height()/$(this).width()) * size);
}
$(this).css({ "height": h, "width": w });
});
问题是小图像被放大。没问题,如果陈述应该照顾的话,还有一个问题!
var size = 350;
$("img").each(function() {
if ($(this).height() > size || $(this).width() > size) { //Always false
if ($(this).height() > $(this).width()) {
var h = size;
var w = Math.ceil(($(this).width()/$(this).height()) * size);
}
else {
var w = size;
var h = Math.ceil(($(this).height()/$(this).width()) * size);
}
$(this).css({ "height": h, "width": w });
}
});
我在哪里错了?
图像的大小(高度/宽度)是多少? – 0x499602D2
您是否尝试“提醒()”这些值?也许他们是'空'? –
图像有各种尺寸。该源代码是chat.stackoverflow.com中的已知邮件的抓取。所以无论人发布什么。 – Billdr