<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
<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);
opacity: 0.5;
display: none;
position: absolute;
top: 0px;
left: 0px;
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; 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"
>
function
showOverlay() {
$(
"#overlay"
).height(document.body.scrollHeight);
$(
"#overlay"
).width(document.body.scrollWidth);
$(
"#overlay"
).fadeTo(200, 0.5);
$(window).resize(
function
(){
$(
"#overlay"
).height(document.body.scrollHeight);
$(
"#overlay"
).width(document.body.scrollWidth);
});
}
function
hideOverlay() {
$(
"#overlay"
).fadeOut(200);
}
</script>
</head>
<body>
<button onClick=
"showOverlay();"
style=
" 100px; height:60px; margin:40px auto 40px auto; display:block;"
>打开遮罩层</button>
<button onClick=
"hideOverlay();"
style=
" 100px; height:60px; z-index:101; display:block; position:absolute; left:10px; top:10px;"
>关闭遮罩层</button>
<div style=
"height:10000px;"
></div>
<div id=
"overlay"
></div>
</body>
</html>