<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RunJS</title>
<style type="text/css">
body, html {
height:100%;
overflow: hidden;
}
h4, body { margin: 0; }
button{
border:1px solid #ccc;
cursor:pointer;
display:block;
margin:auto;
position:relative;
top:100px;
}
.bg-lay {
background-color: #000;
opacity: 0.2;
height: 100%;
position: absolute;
width: 100%;
display: none;
top: 0;
z-index: -1;
}
.text-lay {
width: 17%;
background-color: red;
height: 194px;
margin: 188px auto;
display: none;
}
.lay-hd { overflow: hidden; padding: 10px; }
.lay-bd { padding: 10px; border-top: 1px solid #000; }
h4 { float: left; }
span { float: right; }
</style>
</head>
<body>
<button>弹出层!</button>
<div class="text-lay">
<div class="lay-hd">
<h4>
标题信息
</h4>
<span>X</span>
</div>
<div class="lay-bd">
信息内容
</div>
</div>
<div class="bg-lay">
</div>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
<script>
$("button").on("click", function(){
$(".bg-lay").show();
$(".text-lay").show();
});
$("span").on("click", function(){
$(".text-lay").hide();
$(".bg-lay").hide();
})
</script>
</body>
</html>
原文:http://www.cnblogs.com/samtrybest/p/5071481.html