div遮罩层盖住可视或整个

  • Post author:
  • Post category:其他


<!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层,可选择遮罩当前或全部页面 - Liehuo.Net</title>
<meta charset="gbk" />
<style>
div{position:absolute;top:0;left:0;background:#ccc;}
</style>
</head>
<body>
<div id="zhezhao"></div>
<input  type="button" value="盖住整个页面"/>
<input  type="button" value="盖住可视的部分"/>
<p style="height:1800px;"></p>
</body>
</html>
<script>
function zhezhao(f){
var d = document.getElementById('zhezhao'),wh = getWH(f);
d.style.cssText +=";width:"+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://blog.51cto.com/leezhxing/1316544


关闭菜单