窗口调整大小问题
我想留出一个网络浏览器调整边距。我使用windowResize,但是即使自定义单击网络浏览器的恢复按钮,如何调整左侧边距?我上传了 2 张屏幕截图进行解释。 第一张图片,我打开网络浏览器而不是最大化,因此页面进行了窗口调整大小并计算了左边距,然后我单击窗口最大化,然后获取 第二张图片,但内容不在页面中心。如何正确调整窗口大小?谢谢。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
var width = document.body.clientWidth;
windowResize(width);
$(window).resize(function() {
windowResize(width);
});
});
function windowResize(width) {
if(width>1024){
$('#content').css({
'margin-left':(width-1024)/2+32 + 'px'
});
}else{
$('#content').css({
'margin-left': 32 + 'px'
});
}
}
</script>
</head>
<body>
<style>
body, #box{min-width:1024px;width:100%;}
#content{float:left;width:960px;height:300px;background-color:#F00;}
</style>
<div id="box">
<div id="content">
some words
</div>
</div>
</body>
</html>
I want to make a web browser adjustment margin left. I use windowResize, but how to adjustment margin left even if the custom click the restore button of the web browser? I upload 2 screenshort images for explain. first image, I open the web browser not maximize, so the page make a windowResize and count the margin-left, then I click the windows maximize, then get the second image, but the content is not in the center of the page. How to do a right windowResize? Thanks.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
var width = document.body.clientWidth;
windowResize(width);
$(window).resize(function() {
windowResize(width);
});
});
function windowResize(width) {
if(width>1024){
$('#content').css({
'margin-left':(width-1024)/2+32 + 'px'
});
}else{
$('#content').css({
'margin-left': 32 + 'px'
});
}
}
</script>
</head>
<body>
<style>
body, #box{min-width:1024px;width:100%;}
#content{float:left;width:960px;height:300px;background-color:#F00;}
</style>
<div id="box">
<div id="content">
some words
</div>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我注意到的一件事是,这段代码只会使用初始宽度调用
windowResize
:我更改了它,以便在
windowResize
内部计算宽度,并且一切正常。One thing I notice is that this code will only ever call
windowResize
with the initial width:I changed it so the width is calculated inside of
windowResize
and things work.