html浮层,设置浮层透明度

使用场景,二维码过期,出现浮层覆盖二维码,并提示二维码失效

<!doctype html>
<html>
    <head>
        <!--引入JQuery文件-->
        <script src="../jquery-3.1.0.min.js"></script>
        <title>浮层的简单原理</title>
        <style>
        /*body初始状态,清间距,设置背景*/
        body
        {
            margin: 0;
            padding: 0;
            background-color: silver;
        }
        /*超链接的样式:蓝色按钮*/
        a
        {
            display: inline-block;
            width: 100px;
            height: 50px;
            font:normal normal normal 18px/50px 'Microsoft Yahei';
            background-color: #00b3ee;
            text-align: center;
            margin: 100px 200px;
            text-decoration: none;
            border-radius: 5px;
        }
        /*人为制造一个占据整个屏幕的Div,其透明度为0.7且z-index为9999使之前的页面被压在底层无法点击*/
        #fullScreen
        {
            position: fixed;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;
            opacity: 0.7;
            background-color: red;
            z-index: 9999;
        }
        /*浮层,可随意设置大小宽高,但是z-index必须比上面fullScreen大才能显示出来*/
        #floatLayer
        {
            position: fixed;
            width: 200px;
            height: 200px;
            left: 34%;
            top: 15%;
            background-color:rgba(00,22,33,0.5);
            z-index: 10000;
        }
        </style>
    </head>
    <body>
        <a href="#" id="show">出现浮层</a>
    </body>
</html>
<script>
    $("document").ready(function()
    {
        //点击弹出浮层
        $("#show").click(function()
        {
            //清除之前的样式
            $("#fullScreen,#floatLayer").remove();
            $("body").append
            (
                //占据整个屏幕Div
                "<div id='fullScreen'></div>"+
                //浮层区
                "<div id='floatLayer'>" +
                    "<a href='#' id='hide'>隐藏浮层</a>"+
                "</div>"
            );
            //隐藏浮层
            $("#hide").click(function()
            {
                $("#fullScreen,#floatLayer").remove();
            });
        });
    });
</script>

1、设置两个div
2、给每个div都设置样式,并且赋予不同颜色好区分
3、给浮层设置背景颜色的时候,使用background-color:rgba(00,22,33,0.5);
4、这里有个要注意的点是,浮层的层级一定要比页面高才行z-index: 10000;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值