两个常用的DIV弹出层效果代码(遮挡整个页面,遮挡可视部分)

<!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>
<title>DIV弹出层</title>
<meta charset="gbk" />
<style>
  div{
   position:absolute;
   top:0;
   left:0;
   background:#ccc;
  }
 </style>
</head>
<body>
 <div id="test"></div>
<input onclick="test1()" type="button" value="盖住整个页面"/>
<input onclick="test1(1)" type="button" value="盖住可视的部分"/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</body>
</html>
 <script>
  function test1(f){
   var d = document.getElementById('test'),wh = getWH(f);
   d.style.cssText +=";"+wh.w+'px;height:'+wh.h+'px'
  }
  var getWH = function (){
   var d = document,doc = d[d.compatMode == "CSS1Compat"?'documentElement':'body'];
   return function(f){
    return {
     w:doc[(f?'client':'scroll')+'Width'],
       h:f?doc.clientHeight:Math.max(doc.clientHeight,doc.scrollHeight)
    }
   }
  }()
 </script>
原文地址:https://www.cnblogs.com/liufei88866/p/1914375.html