jquery界面点击按钮弹出悬浮框

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

jquery界面点击按钮弹出悬浮框

lbb-luckly   2022-05-28 我要评论

首先定义两个div:

一个是背景,一个是悬浮窗。

<input id="Button1" type="button" value="点击弹出层"/>       
        <!--弹出层时背景层DIV-->
        <div id="fade" class="black_overlay"></div>
        <!-- 编辑框 可以加自己的样式 -->
        <div id="MyDiv" class="white_content">
            点击阴影处退出!!!
</div>

css样式:

<style>
            .black_overlay {
            display: none;
            position: absolute;
            top: 0%;
            left: 0%;
            width: 100%;
            height: 100%;
            background-color: black;
            z-index: 1001;
            -moz-opacity: 0.8;
            opacity: .80;
            filter: alpha(opacity=80);
        }

        .white_content {
            display: none;
            position: absolute;
            top: 10%;
            left: 10%;
            width: 80%;
            height: 80%;
            border: 16px solid lightblue;
            background-color: white;
            z-index: 1002;
            overflow: auto;
        }

        .white_content_small {
            display: none;
            position: absolute;
            top: 20%;
            left: 30%;
            width: 40%;
            height: 50%;
            border: 16px solid lightblue;
            background-color: white;
            z-index: 1002;
            overflow: auto;
        }
</style>

jquery方法:

<script type="text/javascript">
        $("#Button1").click(function() {
            document.getElementById("MyDiv").style.display = 'block';
            document.getElementById("fade").style.display = 'block';
            var bgdiv = document.getElementById("fade");
            bgdiv.style.width = document.body.scrollWidth;
            $("#fade").height($(document).height());
        });
        //关闭弹出层
        $("#fade").click(function() {
            document.getElementById("MyDiv").style.display = 'none';
            document.getElementById("fade").style.display = 'none';
        });
</script>

效果图:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们