jquery遮罩

<!DOCTYPE html>
<html>
<head>
    <title>带遮罩的jQuery弹出框-jQuery在线演示-jQuery学习</title>
    <meta name="keywords" content="jQuery弹出层,jQuery遮罩层"/>
    <meta name="description" content="在线演示jQuery遮罩层效果,jQuery遮罩层在现在的网站中十分常见,今天就简单制作一个jQuery遮罩层,当然也可以做成公共函数,方便以后多次使用.本教程适合新手。"/>
    <link href="http://www.jquery001.com/css/site.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        /* box */
        .box{position:absolute;width:600px;left:50%;height:auto;z-index:100;background-color:#fff;border:1px #ddd solid;padding:1px;}
        .box h2{height:25px;font-size:14px;background-color:#aaa;position:relative;padding-left:10px;line-height:25px;color:#fff;}
        .box h2 a{position:absolute;right:5px;font-size:12px;color:#fff;}
        .box .list{padding:10px;}
        .box .list li{height:24px;line-height:24px;}
        .box .list li span{margin:0 5px 0 0;font-family:"宋体";font-size:12px;font-weight:400;color:#ddd;}
        .showbtn {font:bold 24px '微软雅黑';}
        #bg{background-color:#666;position:absolute;z-index:99;left:0;top:0;display:none;width:100%;height:100%;opacity:0.5;filter: alpha(opacity=50);-moz-opacity: 0.5;}
    </style>
</head>




<body>


<p class="showbtn"><a href="javascript:void(0);">显示遮罩层</a></p>
<div id="bg"></div>
<div class="box" style="display:none">
    <h2>jQuery 学习交流<a href="#" class="close">关闭</a></h2>
    <div class="list">
        <ul>
            <li>我是稀饭</li>
            <li>我是稀饭</li>
            <li>我是稀饭</li>
        </ul>
    </div>
</div>
<script src="http://libs.baidu.com/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>


<script type="text/javascript">
        $(function () {
            $(".showbtn").click(function () {
                $("#bg").css({
                    display: "block", height: $(document).height()
                });
                var $box = $('.box');
                $box.css({
                    //设置弹出层距离左边的位置
                    left: ($("body").width() - $box.width()) / 2 - 20 + "px",
                    //设置弹出层距离上面的位置
                    top: ($(window).height() - $box.height()) / 2 + $(window).scrollTop() + "px",
                    display: "block"
                });
            });
            //点击关闭按钮的时候,遮罩层关闭
            $(".close").click(function () {
                $("#bg,.box").css("display", "none");
            });
        });
    </script>   
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值