首页 > 其他 > 详细

遮罩层的实现

时间:2017-12-13 19:01:11      阅读:214      评论:0      收藏:0      [点我收藏+]

一、方法一

#cover{
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #000;
    opacity: 0.5;
    -webkit-filter: alpha(opacity=50);
    -moz-filter: alpha(opacity=50);
    filter: alpha(opacity=50);
    z-index: 2;
}

若用此方法,拉动滚动条时会出现页面下部遮罩层盖不住的情况,原因在于position取值为absolute,此时可以结合js或者jquery动态设置遮罩层的宽和高,从而实现全覆盖:

$("#cover").css({ "width": $(document).width(), "height": $(document).height() });

 

document.getElementById("cover").style.width = document.documentElement.clientWidth|document.body.clientWidth+"px";

document.getElementById("cover").style.height = document.documentElement.clientHeight|document.body.clientHeight+"px";

 

 二、方法二

     或者直接给position取值为 fixed,避免页面的滚动

#cover{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #000;
    opacity: 0.5;
    -webkit-filter: alpha(opacity=50);
    -moz-filter: alpha(opacity=50);
    filter: alpha(opacity=50);
    z-index: 2;
}

 

遮罩层的实现

原文:http://www.cnblogs.com/bluecoding/p/8034146.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!