一个DIV小弹窗 JS实现

今天,试了一个小弹窗功能,可以在新增之类的方面加入。

代码如下:

CSS样式,放<head>中

 <style type="text/css">
#topCoverDiv
        {
            opacity: 0.4;
            position: absolute;
            width: 300%; /*阴影大小*/
            height: 500%;
            top: 0px;
            background-color: #000;
            z-index: 100;
        }
#dia
        {
            clear: left;
            float: left;
            background: rgba(0,0,0,0.5);
            z-index: 100;
            position: absolute;
            top: 5%; /*外相对距离*/
            left: 20%;
            width: 600px; /*大小高度*/
            height: 400px;
            margin: -20px 0 0 -25px; /*内相对距离*/
            border-radius: 10px; /*外框润滑度*/
            border-top-width: 10px;
            padding: 10px 10px 10px 10px; /*内框距离*/
        }
</style>

<body>中控件

<a onclick="test()">新增</a>
//引用方法



/*弹窗*/
<div id='dia' style="display: none;">
            <div style="background-color: #fff; opacity: 1; z-index: 19891015;" class="xubox_main">
                <div class="xubox_title" style="background: rgb(219, 219, 219);" move="ok">
                    <em id="LittleTitle">新增</em> <a onclick='test()' style="font-size: 18px; 
                        margin-left: 480px; cursor: default;">X</a>
                </div>
                <div>
                    <iframe src='ShenHeIntegration.aspx' name="If1" style="width: 500px; height: 
                       350px;">//iframe弹窗
                    </iframe>
                </div>
            </div>
        </div>

JS代码实现

<script type="text/javascript">
    
    function test() {
        var maskBg = document.getElementById('topCoverDiv')
        var dia = document.getElementById('dia')
        maskBg.style.display = (maskBg.style.display == 'none') ? 'block' : 'none';
        dia.style.display = (dia.style.display == 'none') ? 'block' : 'none';
    }
</script>

这样就完成了一个界面小弹窗功能。

完整html代码如下:

<html>
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        #topCoverDiv
        {
            opacity: 0.4;
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0px;
            background-color: #000;
            z-index: 100;
            text-align: center;
        }
        
        #dia
        {
            clear: left;
            float: left;
            background: rgba(0,0,0,0.5);
            z-index: 200;
            position: absolute;
            top: 50%;
            left: 50%;
            width: 500px;
            height: 400px;
            margin: -200px 0 0 -250px;
            border-radius: 10px;
            border-top-width: 10px;
            padding: 10px 10px 10px 10px;
        }
    </style>
</head>
<body>
    <a onclick='test()' >点我</a>
<div id='topCoverDiv' style="display: none;">
    </div>
    <div id='dia' style="display: none;">
        <div style="background-color: #fff; opacity: 1; z-index: 19891015;" class="xubox_main">
            <div class="xubox_title" style="background: rgb(219, 219, 219);" move="ok">
                <em id="LittleTitle">新增</em> <a onclick='test()' style="font-size: 18px; margin-left: 480px;
                    cursor: default;">X</a>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    function test() {
        var maskBg = document.getElementById('topCoverDiv')
        var dia = document.getElementById('dia')
        maskBg.style.display = (maskBg.style.display == 'none') ? 'block' : 'none';
        dia.style.display = (dia.style.display == 'none') ? 'block' : 'none';
    }
</script>

可以去试试

转载于:https://my.oschina.net/aidaidai/blog/2051586

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值