定义两个div并定义id,
第一个div设置遮罩层样式,top:0;上下左右都设置为0,设置z-index=10,加上透明度opacity。display:none
第二个div设置弹出框样式,z-index=11;display:none
当被点击实现function open(),用var id1=document.getElmentById(’’),id1.style.display=block
完整代码附上
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
<style>
#box{
height:240px;
width:300px;
margin:0 auto;
border:1px solid #0066FF;
overflow:hidden;
padding-bottom:20px;
}
#popLayer {
display: none;
background-color: #B3B3B3;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 10;
-moz-opacity: 0.8;
opacity:.80;
filter: alpha(opacity=80);/* 只支持IE6、7、8、9 */
}
#popBox {
display: none;
background-color: #FFFFFF;
z-index: 11;
width: 550px;
height: 350px;
padding: 20px;
position:fixed;
top:0;
right:0;
border-radius: 10px;
left:0;
bottom:0;
margin:auto;
}
#popBox .close{
text-align: right;
margin-right: 5px;
background-color: #F8F8F8;
}
#popBox .close a {
text-decoration: none;
color: #2D2C3B;
font-size: 14px;
}
</style>
</head>
<body>
<div id="box">
<button onclick="popBox()">弹出框</button>
<div id="popLayer"></div>
<div id="popBox">
<h4 style="margin: 5px">分享二维码</h4>
<div class="close">
<a href="javascript:void(0)" onclick="closeBox()">关闭</a>
</div>
</div>
</div>
</div>
<script>
/*点击弹出按钮*/
function popBox() {
var popBox = document.getElementById("popBox");
var popLayer = document.getElementById("popLayer");
popBox.style.display = "block";
popLayer.style.display = "block";
};
/*点击关闭按钮*/
function closeBox() {
var popBox = document.getElementById("popBox");
var popLayer = document.getElementById("popLayer");
popBox.style.display = "none";
popLayer.style.display = "none";
}
</script>
</body>
</html>