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;

            padding: 0px;

            margin: 0px;

        }

        body, th, td, input, button, textarea

        {

            font-family: "宋体";

            font-size: 12px;

        }

        

        .over_main

        {

            background: white;

            position: absolute;

            width: 600px;

            height: 400px;

            border: 1px solid lightblue;

            margin: 10px;

            overflow: auto;

        }

        .over_main p

        {

            margin: 0px;

            padding: 3px;

            background: #BCDAF0;

        }

        .over_products

        {

            padding-top: 5px;

            padding-left: 10px;

        }

        .over_searchResults li

        {

            list-style: none;

        }

        

        .over_close

        {

            float: right;

            margin-top: -18px;

            padding-right: 5px;

            cursor: pointer;

        }

        .over_cover

        {

            background: gray;

            position: absolute;

            top: 0px;

            left: 0px;

            opacity: 0.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>

效果图:

时间: 2024-08-03 14:33:00

jquery弹窗遮罩的相关文章

Jquery实现遮罩层的方法_jquery

本文实例讲述了Jquery实现遮罩层的方法.分享给大家供大家参考.具体如下: 1.假设#main为页面body中的最外层Div标签 2.背景被遮罩后,显示的弹出窗(默认是不显示的,所包含的CSS这里就不贴了): <!-- Status Bar Start --> <div id="warning-dialog" class="status warning center-top no-display"> <p class="cl

Jquery实现遮罩层的方法

  本文实例讲述了Jquery实现遮罩层的方法.分享给大家供大家参考.具体如下: 1.假设#main为页面body中的最外层Div标签 2.背景被遮罩后,显示的弹出窗(默认是不显示的,所包含的CSS这里就不贴了): ? 1 2 3 4 5 6 7 8 9 10 11 <!-- Status Bar Start --> <div id="warning-dialog" class="status warning center-top no-display&qu

使用jQuery制作遮罩层弹出效果的极简实例分享_jquery

客户的网站上突然需要一个遮罩弹窗效果,也可以称作暗箱之类的,具体效果就是网页中背景变成半透明,然后在屏幕中间出现一个菜单之类的东西.这种效果在网上很常见,例如:QQ空间浏览相册等.这种效果的好处就是,可以让用户聚焦到弹出的菜单中. 神说,有代码的文章,应该有个 Demo ,于是就有了Demo. HTML 结构 首先先来分析一下这个过程:触发某个事件(例如点击按钮),然后出现一个背景遮罩上面还有一个内容层.触发的按钮,我在这里用 div 来代替,并且使用 click 点击事件来演示.那么我们的 H

jquery弹窗插件colorbox绑定动态生成元素的方法_jquery

colorbox是jquery一个非常好用的弹窗插件,功能十分丰富,使用体验也很好. colorbox官网:http://www.jacklmoore.com/colorbox/ 刚才在是用colorbox的时候遇到了一个问题,这个问题以前没有注意过. 以前我都是讲这个插件使用在静态HTML元素中的,今天为动态生成的元素绑定的时候发现不能用了. 常规的用法是这样的: 复制代码 代码如下: <a class="test" href="test.jpg" titl

jquery blockUI 遮罩不能消失与不能提交的解决方法_jquery

复制代码 代码如下: //显示遮罩 $.blockUI({ message: $('#divlogin'), css:{width:"400px", height:"255px", top: ($(window).height() - 400) /2 + 'px', left: ($(window).width() - 400) /2 + 'px'} }); //取消遮罩 $("#cancel").click(function() { $.unb

jquery blockUI 遮罩不能消失与不能提交

本文章介绍一下关于 blockUI 遮罩不能消失与不能提交原因与解决方法,有需要的朋友可以参考一下. 显示遮罩 $.blockUI({ message: $('#divlogin'), css教程:{width:"400px", height:"255px", top: ($(window).height() - 400) /2 + 'px', left: ($(window).width() - 400) /2 + 'px'} }); //取消遮罩 $("

jquery 圆角遮罩图片实现图片圆角_jquery

基于jQuery实现弹出可关闭遮罩提示框实例代码_jquery

jquery CSS3遮罩弹出层动画效果,使用非常简单,就两个标签,里面自定义内容和样式,四种常见效果,懂的朋友还可以修改源代码修改成自己想要的效果 先给大家展示下效果图,如果大家感觉还不错,请参考实现代码. 效果演示 关键代码如下所示: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo

jquery实现简单的遮罩层_javascript技巧

本文实例讲解了jquery遮罩层,包括遮罩层的不同样式实现.mask实现遮罩层等,分享给大家供大家参考,具体内容如下 一.jQuery实现遮罩层的不同样式1.1 背景半透明遮罩层样式 需要一个黑色(当然也可以其他)背景,且须设置为绝对定位,以下是项目中用到的css样式: /* 半透明的遮罩层 */ #overlay { background: #000; filter: alpha(opacity=50); /* IE的透明度 */ opacity: 0.5; /* 透明度 */ display