原生JS+CSS(CSS3)+HTML实现页面弹框

<!DOCTYPE html>
 <html>
 <head>
 <meta charset=""/>
 <title>opacity</title>
 <style>
 *{
     padding: 0;
     margin: 0;
}
body{
    padding: 0px;
    background: url() 0 0 no-repeat;
    background-size: cover;
}

.demo{
    width: 100%;
    height: 100%;
    position: relative;
}
.demo-bg{
    position: absolute;
    left: 0;
    top: 0;
    z-index: 0;
    width: 100%;
    height: 671px;
    /*filter:Alpha(opacity=50);*/
    background-color: rgba(0,0,0,0.4); /*实现透明背景*/
    display: none;
}
#button{
    width: 70px;
    height: 30px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    background: yellow;
    margin: 20px 0 0 40px;
    position: relative;
    border: 0;
    box-shadow:  2px 2px 10px red;
    -webkit-box-shadow:  2px 2px 10px red;
    -moz-box-shadow:  2px 2px 10px red;
}
.demo-txt{
    position: relative;
    z-index: 1;
    color: #000;
    background: white;
    width: 30%;
    height: 200px;
    margin:auto;
    padding: auto;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    display: none;
    padding: 10px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
}
#btn{
    float: right;
}
</style>
</head>
<body>   

<div class='demo'>
    <button id="button" onclick="openDialog()">打开弹窗</button>
    <div class='demo-bg'></div>
    <div class='demo-txt'>
        <button id="btn" onclick="closeDialog()">关闭弹窗</button>
    </div>
</div>
<script>
    var demobg = document.querySelector(".demo-bg");
    var demotxt = document.querySelector(".demo-txt");
    function openDialog() {
        demotxt.style.display = "block";
        demobg.style.display = "block";
    }

    function closeDialog() {
        demotxt.style.display = "none";
        demobg.style.display = "none";
    }
</script>
 </body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值