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>

效果图:


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值