• html、css、js原生的弹窗功能


    有时候,我们在写项目的时候使用框架里的弹窗,并不能满足客户的需求,
    又或者使用地框架有冲突的时候,这时我们只能使用原生的css,js去写一个弹窗。

    <!DOCTYPE html>
    
    <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>原生的弹窗</title>
        <style>
            /* 遮挡层样式 */
            .dialog-face {
                position: fixed;
                height: 100%;
                width: 100%;
                z-index: 10;
                top: 0;
                left: 0;
                opacity: 0.5;
                background: #000000;
            }
    
            /* 弹窗样式 */
            .bg {
                width: 500px;
                height: 400px;
                background-color: white;
                border-radius: 5px;
                box-shadow: 0px 3px 8px 0px rgba(0, 0, 0, 0.2);
                /* 定位 居中 */
                position: absolute;
                left: 50%;
                top: 50%;
                margin-top: -200px;
                margin-left: -250px;
                /* 显示级别 */
                z-index: 11;
            }
    
            /* 弹窗标题 */
            .title {
                color: #000000;
                text-align: center;
                height: 50px;
                line-height: 50px;
                cursor: move;
                /*光标的样式*/
                padding: 0;
                font-size: 22px;
            }
    
            /* 弹窗上的关闭元素样式 */
            .close {
                position: absolute;
                right: 6px;
                top: -10px;
                cursor: pointer;
                text-decoration: none;
            }
        </style>
    </head>
    
    <body>
    
        <button onclick="openPopup()">打开弹窗</button>
    
        <!-- 弹窗 -->
        <div id="popup" style="display: none;">
            <!-- 弹窗遮蔽层 -->
            <div class="dialog-face">
    
            </div>
            <!-- 弹窗内容层 -->
            <div class="bg">
    
                <div class="title">弹窗标题
                    <div class="close" onclick="closePopup()">&times;</div>
                </div>
                <div class="">
                    这是一个弹窗ヾ(≧∇≦*)ゝ
                </div>
            </div>
        </div>
    
    </body>
    <script src="../js/jquery.min.js"></script>
    <script>
        // 打开弹窗
        function openPopup() {
            var popup = document.getElementById("popup")
            popup.style.display = 'block';
        }
    
        // 关闭弹窗
        function closePopup() {
            var popup = document.getElementById("popup")
            popup.style.display = 'none'
        }
    
        //点击遮蔽层关闭
        $(".dialog-face").click(function () {
            $("#popup").attr("style", "display:none")
        })
    
    </script>
    
    </html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
  • 相关阅读:
    Redis学习笔记——初识Redis
    TCP三次握手和四次挥手详解
    gRPC 健康检查
    记录一次最近遇到的新网络诈骗经历,大家要提高警惕啊
    归并排序 刷题笔记
    Skywalking介绍
    AD9371 官方例程HDL详解之JESD204B TX侧时钟生成 (二)
    模拟量偏差报警功能块(SCL代码)
    TCP案例-实时群聊
    kafka-console-producer.sh
  • 原文地址:https://blog.csdn.net/xt314159/article/details/125522306