HTML
<div class="header">Header</div>
<div class="body">
<table class="body-table">
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
<tr>
<td>Cell</td>
<td>Cell</td>
<td>Cell</td>
</tr>
</table>
</div>
<div class="footer">
<button>Submit</button>
</div>
CSS
.header{
height:50px;
background-color:#ccc;
width:500px;
}
.body{
width:500px;
max-height:600px;
text-align:center;
background-color:#ddd;
overflow:auto;
}
.body .body-table{
border-collapse:collapse;
text-align:center;
margin:0 auto;
width:100%;
}
.footer{
width:500px;
height:50px;
background-color:#eee;
}
查询
var windowHeight = $(window).height();
$(window).resize(function(){
if(windowHeight<600+'px'){
$('.body').height($('.body').height()-20+'px');
}
});
JSfiddle
我想根据调整窗口大小来增加和减少。如果窗口高度<600 减少 .body div 高度或窗口高度>600 增加。但我做不到。我的 jquery 代码不起作用我该怎么做?