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