本文主要介绍了jquery实现可兼容ie6的遮罩功能,详细分析了jquery遮罩层的布局、样式及功能实现技巧,需要的朋友可以参考下,希望能帮助到大家。
最精简,最强大的 jquery 遮罩层效果。
当浏览器改变大小时,遮罩层的大小会相应地改变。
遮罩层上方的对话框可随 scroll 的改变而改变,即对话框在浏览器居中显示。
html 代码
<p id="main"><a onclick="showbg();" href="#" rel="external nofollow" rel="external nofollow" >点击这里看 jquery 遮罩层效果.</a></p>
<p id="fullbg"></p>
<p id="dialog">
<p class="close"><a onclick="closebg();" href="#" rel="external nofollow" rel="external nofollow" >关闭</a></p>
正在加载,请稍后...
</p>
css 代码
body {
font-family: arial, helvetica, sans-serif;
font-size: 12px;
margin: 0;
}
#main {
height: 1800px;
padding-top: 90px;
text-align: center;
}
#fullbg {
background-color: gray;
left: 0px;
opacity: 0.5;
position: absolute;
top: 0px;
z-index: 3;
filter: alpha(opacity=50); /* ie6 */
-moz-opacity: 0.5; /* mozilla */
-khtml-opacity: 0.5; /* safari */
}
#dialog {
background-color: #fff;
border: 1px solid #888;
display: none;
height: 200px;
left: 50%;
margin: -100px 0 0 -100px;
padding: 12px;
position: fixed !important; /* 浮动对话框 */
position: absolute;
top: 50%;
width: 200px;
z-index: 5;
}
#dialog p {
margin: 0 0 12px;
}
#dialog p.close {
text-align: right;
}
jquery 代码
<script type="text/javascript" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
//显示灰色 jquery 遮罩层
function showbg() {
var bh = $("body").height();
var bw = $("body").width();
$("#fullbg").css({
height:bh,
width:bw,
display:"block"
});
$("#dialog").show();
}
//关闭灰色 jquery 遮罩
function closebg() {
$("#fullbg,#dialog").hide();
}
</script>
<!--[if lte ie 6]>
<script type="text/javascript">
// 浮动对话框
$(document).ready(function() {
var domthis = $('#dialog')[0];
var wh = $(window).height() / 2;
$("body").css({
"background-image": "url(about:blank)",
"background-attachment": "fixed"
});
domthis.style.setexpression('top', 'eval((document.documentelement).scrolltop + ' + wh + ') + "px"');
});
</script>
<![endif]-->
这里别忘记引入jquery文件。
相关推荐:
js实现鼠标放到图片上产生遮罩效果的代码案例
如何阻止遮罩层后页面滚动的实例
什么是js特效遮罩层
以上就是jquery实现可兼容ie6的遮罩功能实例分享的详细内容。
