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>
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值