日期:2014-05-18  浏览次数:20655 次

求高手一段JS代码!
JS控制页面大小.使页面内容随窗口大小自适应.

现有这段页面代码.它的JS应该怎么写呢?

页面效果可参照       www.126.com首页效果.

请大虾们帮忙了.

代码如下:  

<!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=gb2312 "   />
<title> 无标题文档 </title>
<style   type= "text/css ">
<!--
*{
margin:0;
padding:0;
}
body   {
font-size:12px;
background:#fff;
}
#col{
width:100%;
margin:0   auto;
}
#top{
width:500px;
height:130px;
margin:0   auto;
padding:10px;
background:#66CCFF;
}
#content{
width:500px;
height:350px;
margin:0   auto;
padding:10px;
}
#footer{
width:500px;
height:130px;
margin:0   auto;
padding:10px;
background:#66CCFF;
}
-->
</style> </head>

<body>
<div   id= "top "> <h1> logo </h1> </div>
<form   id= "form1 "   name= "form1 "   method= "post "   action= " "> <div   id= "content "> 公测用户 <input   type= "submit "   name= "Submit "   value= "立即登录 "   /> </div> </form>
<div   id= "footer "> 版权信息 </div>
</body>
</html>

------解决方案--------------------
<!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=gb2312 " />
<title> 无标题文档 </title>
<style type= "text/css ">
<!--
*{
margin:0;
padding:0;
}
body {
font-size:12px;
background:#fff;
}
#col{
width:100%;
margin:0 auto;
}
#top{
margin:0 auto;
padding:10px;
background:#66CCFF;
}
#content{
margin:0 auto;
padding:10px;
}
#footer{
margin:0 auto;
padding:10px;
background:#66CCFF;
}
-->
</style>
<script>
function resizeDiv()
{
var documentWidth = document.documentElement.clientWidth;
document.getElementById( "top ").style.width = document.getElementById( "footer ").style.width = document.getElementById( "content ").style.width = documentWidth -20;

var documentHeight = document.documentElement.clientHeight;
document.getElementById( "top ").style.height = document.getElementById( "footer ").style.height = parseInt(documentHeight * 0.25);
document.getElementById( "content ").style.height = parseInt(documentHeight * 0.5) - 60;
}
window.onload = window.onresize = resizeDiv;
</script>
</head>

<body>
<div id= "top "> <h1> logo </h1> </div>
<form id= "form1 "