/* 半透明的遮罩层 */
#overlay {
background: #000;
filter: alpha(opacity=50); /* IE的透明度 */
opacity: 0.5; /* 透明度 */
display: none;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 100; /* 此处的图层要大于页面 */
display: none;
}
#msg {
width: 100px;
height: 100px;
background-color: red;
top: 50%;
left: 50%;
position: absolute;
display: none;
z-index: 101; /* 此处的图层要遮盖层 */
}
$(function () {
//点击按钮弹出遮罩
$("#btn1").click(function () {
var pageHeight = window.screen.availHeight;
var pageWidth = window.screen.availWidth;
$("#overlay").height(pageHeight);
$("#overlay").width(pageWidth);
// fadeTo第一个参数为速度,第二个为透明度
// 多重方式控制透明度,保证兼容性,但也带来修改麻烦的问题
$("#overlay").fadeTo(200, 0.5);
$("#msg").show();
});
//关闭遮盖层
$("#btn2").click(function () {
$("#overlay").fadeOut(200);
$("#msg").hide();
});
});
关闭
显示