首页 >  毕业设计知识  > 正文

JS控制DIV随分辩率既浏览器高度变化而变化,可设百分比

<html>
  <head>
    <title>Test by Josh</title>
    <style type="text/css">
      * { padding:0; margin:0; }
      #test { background:#aaa; height:100%; width:100%; }
    </style>
    <script type="text/javascript">
      window.onload = function() {
        var height = getViewportHeight();

        alert("这是脚本运行前的效果。点“确定”查看运行后的效果。");

        if(height > 0)
          document.getElementById("test").style.height = height + "px";
      }

      function getViewportHeight() {
        var h = 0;

        if(self.innerHeight)
          h = window.innerHeight;
        else if(document.documentElement && document.documentElement.clientHeight)
          h = document.documentElement.clientHeight;
        else if(document.body) 
          h 
= document.body.clientHeight;

        return h;
      }
    </script>
  </head>
  <body>
    <div id="test">
      <h1>Test</h1>
    </div>
  </body>
</html>

以上是本题目部分介绍,若需要完整版或不符合您的要求,请联系客服QQ:242219979

上一篇:ASP.NET"正在中止线程"错误原因

下一篇:html 字母太长页面撑大换行问题

相关文章: