zoukankan      html  css  js  c++  java
  • jquery弹窗遮罩

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>jquery弹窗遮罩</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <style type="text/css">
            body
            {
                background#ffffff;
                padding0px;
                margin0px;
            }
            bodythtdinputbuttontextarea
            {
                font-family"宋体";
                font-size12px;
            }
            
            .over_main
            {
                backgroundwhite;
                positionabsolute;
                width600px;
                height400px;
                border1px solid lightblue;
                margin10px;
                overflowauto;
            }
            .over_main p
            {
                margin0px;
                padding3px;
                background#BCDAF0;
            }
            .over_products
            {
                padding-top5px;
                padding-left10px;
            }
            .over_searchResults li
            {
                list-stylenone;
            }
            
            .over_close
            {
                floatright;
                margin-top-18px;
                padding-right5px;
                cursorpointer;
            }
            .over_cover
            {
                backgroundgray;
                positionabsolute;
                top0px;
                left0px;
                opacity0.75;
            }
        </style>
    </head>
    <body>
        <input type="button" value="弹窗遮罩" id="test" />
        <div class="over_main">
            <p>
                选择商品</p>
            <span class="over_close">关闭</span>
            <div class="over_products">
                按
                <select id="selectItem">
                    <option>商品名称</option>
                    <option>商品Id</option>
                    <option>SiebelId</option>
                    <option>淘宝商家编码</option>
                    <option>淘宝商家Sku编码</option>
                </select>
                <input type="text" id="TxtSearchKeyWord" style="width: 200px;" />
                <input type="button" id="btnSearChchooseProducts" value="查询"></input>
                <div class="over_searchResults">
                    <ul>
                        <li>没找到符合条件的任何记录!</li></ul>
                </div>
            </div>
        </div>
        <div class="over_cover">
        </div>
        <script type="text/javascript">
            $(function () {
                $("#test").click(function () {
                    adjust();
                });
                $(".over_cover").click(function () {
                    showMask(false);
                });
                $(".over_close").click(function () {
                    showMask(false);
                });
            });
            function showMask(isShow) {
                var winW = $(window).width();
                var winH = $(window).height();
                $(".over_cover").css("width", winW + "px");
                $(".over_cover").css("height", winH + "px");
                $(".over_cover").css("background""gray");
                if (isShow) {
                    $(".over_main").show();
                    $(".over_cover").show();
                } else {
                    $(".over_main").hide();
                    $(".over_cover").hide();
                }
            }
            function adjust() {
                //取得当前宽度和高度
                var w = $(".over_main").css("width").replace(/px/g, "");
                var h = $(".over_main").css("height").replace(/px/g, "");
                //定位这个盒子,相对于窗口垂直居中
                var winW = $(window).width();
                var winH = $(window).height();
                var top = (winH / 2) - (h / 2);
                top = top < 0 ? 0 : top;
                var left = (winW / 2) - (w / 2);
                left = left < 0 ? 0 : left;
                //遮罩层
                showMask(true);
                $(".over_main").css("top", top + "px");
                $(".over_main").css("left", left + "px");
                $(".over_main").css("z-index""1");
            }
        </script>
    </body>
    </html>

    效果图:


  • 相关阅读:
    rem是如何实现自适应中的?
    meta基础知识
    JqueryMobile动态生成listView并实现刷新的两种方法
    javascript中for/in循环及使用技巧
    JavaScript中this详解
    使用css实现全兼容tooltip提示框
    如何使用CSS3画出一个叮当猫
    jQuery实现的Div窗口震动效果实例
    jQuery实现动态添加和删除一个div
    js对文章内容进行分页示例代码
  • 原文地址:https://www.cnblogs.com/zhangqs008/p/3618455.html
Copyright © 2011-2022 走看看