<!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 CSS遮罩层</title>
<script language="javascript" type="text/javascript">
function showdiv() {
document.getElementById("bg").style.display = "block";
document.getElementById("show").style.display = "block";
}
function hidediv() {
document.getElementById("bg").style.display = 'none';
document.getElementById("show").style.display = 'none';
}
</script>
<style type="text/css">
#bg{ display: none; position: absolute; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index:1001; -moz-opacity: 0.7; opacity:.70; filter: alpha(opacity=70);}
#show{display: none; position: absolute; top: 25%; left: 22%; width: 53%; height: 49%; padding: 8px; border: 8px solid #E8E9F7; background-color: white; z-index:1002; overflow: auto;}
</style>
</head>
<body>
<input id="btnshow" type="button" value="Show" onclick="showdiv();" />
<div id="bg"></div>
<div id="show">测试
<input id="btnclose" type="button" value="Close" onclick="hidediv();" />
</div>
</body>
</html>
按 Ctrl+C 复制代码

Copy上面的代码到HTML页面即可查看效果。

原理比较简单,就是在页面内先定义好需要显示的DIV和遮罩层的CSS,然后用在onclick事件时,通过JS去控制两个DIV的样式:display='block' or display='none'.就可以实现DIV的显示和隐藏。

注意两个DIV的z-index,显示在最上面的DIV的z-index一定要比遮罩层的z-index大。

最新文章

  1. jenkins,dns错误log过大
  2. 【netty】Netty系列之Netty百万级推送服务设计要点
  3. HDU1695 GCD (欧拉函数+容斥原理)
  4. Selenium2学习-008-WebUI自动化实战实例-006-易迅登录之 frame 处理
  5. Redis报错:WRONGTYPE Operation against a key holding the wrong kind of value 解决处理
  6. 学会简单使用poi进行excel有关操作
  7. 精华阅读第 9 期 |滴滴出行 iOS 客户端架构演进之路
  8. UML进行Linux内核调试
  9. uva 571 素数的性质
  10. offline页面开发常用方法及页面控件验证
  11. 2017 国庆湖南 Day5
  12. 【HDFS API编程】图解客户端写文件到HDFS的流程
  13. CF-517C-思维/math
  14. [CQOI2009]叶子的染色
  15. 20155311《网络对抗》Web基础
  16. 团队项目(第四周之一)—GG队
  17. PHP设计模式系列 - 解释器模式
  18. ls 的详细使用
  19. OpenGL实现3D自由变形
  20. 阅读Configuration源码

热门文章

  1. 神经网络(3)---如何表示hypothesis,如何表示我们的model
  2. Jenkins 参数化构建(Git Parameter)
  3. LOJ P10149 凸多边形的划分 题解
  4. GridView修改含有DropDownList控件列的宽度
  5. 递归函数返回值 undefined
  6. loj #2316
  7. break,continue,return的区别 x
  8. 使用python画一颗圣诞树
  9. NCNN使用总结
  10. 20191214数组习题之三:报数(附pow函数简单用法)