我一直在寻找和即兴发挥,并拿出这样的:jQuery的图像尺寸时,窗口大小
$(window).resize(function() {
function imgResize()
{
if ($("#post_container img").width() > $("#post_container img").height()){
$('#post_container img').css({ 'width': '80%', 'height': 'auto' });
}
else if ($("#post_container img").width() < $("#post_container img").height()){
$('#post_container img').css({ 'width': 'auto', 'height': '80%' });
}
else {
$('#post_container img').css({ 'width': '80%', 'height': 'auto' });
}
}
})
是这样的代码,甚至正确的,因为它应该做的是调整检测窗口时,如果图像肖像或风景,并调整它的大小,使其完全适合屏幕。
您只定义了该功能,但未执行该功能。 – Terry 2013-04-22 05:54:43
您应该将此功能放在'resize'事件之外,并在事件内部调用它。 – Vishal 2013-04-22 05:56:34