HTML-简单的遮罩层实现

CSS部分

<style type="text/css">
#mask
{
    display:none;
    background-color:#000;
    width:100%;
    height:100%;
    top:0;
    left:0;
    position:absolute;
    opacity:0.5;
    /*兼容IE8及以下版本浏览器*/
    filter: alpha(opacity=30);
    z-index:1001;
}

#model
{
    width:600px;
    height:600px;
    background-color:white;    
    margin:auto;
    position:absolute;
    z-index:1003;
    top:0;
    left: 0;
    display:none;
    border: 1px solid rgba(0, 0, 0, 0.2);   
    box-shadow: 0px 3px 9px rgba(0, 0, 0, 0.5);
    border-radius: 6px;
}
#model a
{
    font-size: 18px;
    float:right;
    color: red;
    margin: 10px;
}
</style>

js部分

function showDiv()
{  

    $("#model").css('top',(getWindowInnerHeight() - $("#model").height()) / 2 + 'px');   
    $("#model").css('left',(getWindowInnerWidth() - $("#model").width()) / 2 + 'px'); 

    var s = document.getElementById("mask");
    s.style.display = "block";

    var l = document.getElementById("model");
    l.style.display = "block";

}

function colseDiv()
{  
    var s = document.getElementById("mask");
    s.style.display = "none";

    var l = document.getElementById("model");
    l.style.display = "none";

}

// 浏览器兼容 取得浏览器可视区高度   
function getWindowInnerHeight()
{   
    var winHeight = window.innerHeight   
            || (document.documentElement && document.documentElement.clientHeight)   
            || (document.body && document.body.clientHeight);   
    return winHeight;   

}   

// 浏览器兼容 取得浏览器可视区宽度   
function getWindowInnerWidth()
{   
    var winWidth = window.innerWidth   
            || (document.documentElement && document.documentElement.clientWidth)   
            || (document.body && document.body.clientWidth);   
    return winWidth;   

}   

HTML部分

<div id="mask">
</div>
<div id="model">
    <span><a href="javascript:colseDiv();">关闭</a></span>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值