野生大熊猫

JQ 遮罩层+弹出窗
css:#mask-kk{ position: absolute; top: 0; lef...
扫描右侧二维码阅读全文
23
2018/10

JQ 遮罩层+弹出窗

css:

#mask-kk{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    background: #666;
    opacity: 0.5;
    filter: alpha(opacity=50)-moz-opacity: 0.5;
    display: none;
}
.popup-kk{
    position: absolute;
    left: 50%;
    width: 540px;
    height: 578px;
    background: #fff;
    z-index: 1000;
    display: none;
    border-radius:5px;
}
.close {
    position: absolute;
    top: 21px;
    right: 20px;
    cursor:pointer;
}

HTML:

<p class="btn">请点击显示弹窗</p>
<div id="mask-kk"></div> //遮罩层      
<div class="popup-kk">
    <span class="close">x</span> //关闭按钮
</div>//弹窗

js:

$('.btn').click(function() {
        $('#mask-kk').css({
            display: 'block',
            height: $(document).height()
        })
        var $Popup = $('.popup-kk');
        $Popup.css({
        left: ($('body').width() - $Popup.width()) / 2+ 'px',
        top: ($(window).height() - $Popup.height()) / 2 + $(window).scrollTop() + 'px',
        display: 'block'
        })
        $("body").css({overflow:"hidden"})
    })
$('.close').click(function() {
      $('#mask-kk,.popup-kk').css('display', 'none');
      $("body").css({overflow:""})
})
Last modification:October 23rd, 2018 at 04:12 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment