jQuery弹出遮罩层效果完整示例

<!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>

<meta http-equiv="Content-Type"content="text/html; charset=utf-8"/>

<title>jQuery 遮罩层</title>

<style type="text/css">

/* 半透明的遮罩层 */

#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;

_ padding: 0px 0px 0px 5px; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; border-left: 3px solid rgb(108, 226, 108); line-height: 20px; width: 640px; clear: both; border-radius: 0px !important; border-top: 0px !important; border-right: 0px !important; border-bottom: 0px !important; border-image: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; box-sizing: content-box !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; min-height: auto !important; color: gray !important;">#a0a0a0; /* 解决IE6的不透明问题 */

}

</style>

<script type="text/javascript"src="jquery-1.7.2.min.js"></script>

<script type="text/javascript">

/* 显示遮罩层 */

functionshowOverlay() {

$("#overlay").height(document.body.scrollHeight);

$("#overlay").width(document.body.scrollWidth);

// fadeTo第一个参数为速度,第二个为透明度

// 多重方式控制透明度,保证兼容性,但也带来修改麻烦的问题

$("#overlay").fadeTo(200, 0.5);

// 解决窗口缩小时放大后不全屏遮罩的问题

// 简单来说,就是窗口重置的问题

$(window).resize(function(){

$("#overlay").height(document.body.scrollHeight);

$("#overlay").width(document.body.scrollWidth);

});

}

/* 隐藏覆盖层 */

functionhideOverlay() {

$("#overlay").fadeOut(200);

}

</script>

</head>

<body>

<button onClick="showOverlay();"js string">" width:100px; height:60px; margin:40px auto 40px auto; display:block;">打开遮罩层</button>

<button onClick="hideOverlay();"js string">" width:100px; height:60px; z-index:101; display:block; position:absolute; left:10px; top:10px;">关闭遮罩层</button>

<h3 align="center"><a href="http://www.jb51.net/">阅谁问君诵,水落清香浮。</a></h3>

<div js string">"height:10000px;"></div>

<div js string">"overlay"></div>

</body>

</html>