【发布时间】:2013-04-22 05:52:59
【问题描述】:
我一直在寻找和即兴创作并想出这个:
$(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' });
}
}
})
该代码是否正确,因为它应该做的是在调整窗口大小时检测图像是纵向还是横向并调整其大小以使其完全适合屏幕。
【问题讨论】:
-
你只定义了函数,没有执行。
-
你应该把函数放在
resize事件之外,然后在事件中调用它。