美文网首页
mask 模态弹框

mask 模态弹框

作者: 洪锦一 | 来源:发表于2022-09-15 14:47 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            .mask {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, 0.4);
                z-index: 99999;
                display: none;
            }
    
            .mask .dialog_box {
                width: 600px;
                height: 300px;
                background-color: #FFFFFF;
                position: absolute;
                border-radius: 10px;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
            }
        </style>
    
    </head>
    
    <body>
        <button id="showBtn">显示</button>
        <div class="mask" id="mask">
            <div class="dialog_box">
                <div class="title">
                    <button id="hideBtn">关闭</button>
                </div>
            </div>
        </div>
    </body>
    <script>
        let mask = document.getElementById('mask')
        let showBtn = document.getElementById('showBtn')
        let hideBtn = document.getElementById('hideBtn')
    
        showBtn.onclick = () => {
            mask.style.display = 'block'
        }
        hideBtn.onclick = () => {
            mask.style.display = 'none'
        }
    </script>
    
    </html>
    

    效果图

    相关文章

      网友评论

          本文标题:mask 模态弹框

          本文链接:https://www.haomeiwen.com/subject/kvnrortx.html