jquery 调整窗口大小
我下面有这个脚本,它将在窗口调整大小时调整“.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>
i have this script below that will resize the ".content" on window resize it works fine but the only problem is that it jerks it waits until the resize has finished and then resizes the ".content" is there a wait to smooth the resizing that it resizes while the window resizes?
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该使用 jquery 缓动插件。
http://ajaxmint.com/2009/11/jquery-animation -easing-plugin-example/
这可以使动画平滑。
I think you should use jquery easing plugin.
http://ajaxmint.com/2009/11/jquery-animation-easing-plugin-example/
This smooths the animations.