【发布时间】:2009-12-31 13:45:20
【问题描述】:
我在下面有这个脚本,它将在窗口调整大小时调整“.content”的大小,它工作正常,但唯一的问题是它会一直等到调整大小完成,然后再调整“.content”的大小是否需要等待在窗口调整大小时平滑调整大小?
javascript
function foo(){
//e.cancelBubble = true;
$('.content').each(function (){
p = $('.content').parent();
var ch = 0;
var cw = 0
c = p.children().each(function (i,n){
ch +=$(this).height()
cw +=$(this).width()
});
$(this).height(p.height()-(ch-$(this).height()) )
.width(p.width()-(cw-$(this).width()) )
t = $('#tmp');
t.text('p:height: ' +p.height()+' c:'+ch );
});
}
$(window).resize(foo)
css
html,body{height: 100%; width: 100%; margin: 0; padding: 0; }
.holder{
width: 100%;
height: 100%;
background: yellow;
}
.header{
background-color: red;
}
.footer{
background-color: brown;
}
.content{
background-color: #eeeeee;
}
html
<body onload="foo();" onresize="foo()">
<div class="holder">
<div class="header">
#header
</div>
<div class="content">
#content
<div id="tmp">Waiting...</div>
</div>
<div class="footer">
#footer
</div>
</div>
</body>
【问题讨论】: