写了一个简单好用的弹出层插件

废话不多说,直接上代码:

一、CSS

.overlayBackground {
    top: 0%;
    left: 0%;
    width: 100%;
    height: 100%;
    display: none;
    position: absolute;
    background-color: #555555;
    z-index: 1001;
    -moz-opacity: 0.7;
    opacity: .70;
    filter: alpha(opacity=70);
}
.contentDivDialog {
    display: none;
    position: absolute;
    top: 10%;
    left: 10%;
    border: 16px solid lightblue;
    background-color: white;
    z-index: 1002;
    overflow: auto;
}
View Code

二、插件JS

(function ($) {
    $.fn.YoungDialog = function (options) {
        //Default parameters
        var defaults = {
            //Title: "",
            Width: "80%",
            Height: "80%",
            Modal: true
        };
        //Overwrite by options
        options = $.extend(defaults, options);

        //Show block div
        if (options.Modal&& $("#divBackOverlay").length == 0))
            $("body").append("<div id='divBackOverlay' class='overlayBackground'></div>");
        //Content div
        var divContent = $(this);
        var divOverlay = $("#divBackOverlay");
        divContent.show();
        divOverlay.show();
        //Style
        divContent.addClass("contentDivDialog");
        divContent.css("width", options.Width);
        divContent.css("height", options.Height);

        //Close Button
        divContent.find("#btnCloseDialog").bind("click", function (e) {
            divContent.hide();
            divOverlay.hide();
        });
    };
})(jQuery);
View Code

三、Demo

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../Scripts/jquery-1.7.1.min.js"></script>
    <link href="../Scripts/Custom/YoungDialog.css" rel="stylesheet" />
    <script src="../Scripts/Custom/YoungDialog.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnPopup").click(function () {
                $("#MyDiv").YoungDialog({
                    Width: "500px",
                    Height: "400px",
                    Modal: true
                });
            });
        });
    </script>
</head>
<body>    
    <div>
        <input id="btnPopup" type="button" value="Popup Window" />
    </div>
    <div id="MyDiv" style="display:none;" >
        <div style="text-align: right; cursor: default; height: 40px;">
            <span id="btnCloseDialog" style="font-size: 16px;"> Close </span>
        </div>
        <div>
            My Content can be everything.
        </div>
    </div>
</body>
</html>
View Code

 

转载于:https://www.cnblogs.com/windy2008/p/5760323.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值