jquery 信息提示框对话框 div层实现

效果图:

原网页地址:http://tutorialzine.com/2010/12/better-confirm-box-jquery-css3/

CSS样式:

   #confirmOverlay
        {
            width: 100%;
            height:100%;
            position: fixed;
            top: 0;
            left: 0;
            background: -moz-linear-gradient(rgba(11,11,11,0.1), rgba(11,11,11,0.6)) repeat-x rgba(11,11,11,0.2);
            background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(11,11,11,0.1)), to(rgba(11,11,11,0.6))) repeat-x rgba(11,11,11,0.2);
            z-index: 100000;
        }
        #confirmBox
        {
            background: url('body_bg.jpg') repeat-x left bottom #e5e5e5;
            width: 460px;
            position: fixed;
            left: 50%;
            top: 50%;
            margin: -130px 0 0 -230px;
            border: 1px solid rgba(33, 33, 33, 0.6);
            -moz-box-shadow: 0 0 2px rgba(255, 255, 255, 0.6) inset;
            -webkit-box-shadow: 0 0 2px rgba(255, 255, 255, 0.6) inset;
            box-shadow: 0 0 2px rgba(255, 255, 255, 0.6) inset;
        }
        
        #confirmBox h1, #confirmBox p
        {
            font: 26px/1 'Cuprum' , 'Lucida Sans Unicode' , 'Lucida Grande' , sans-serif;
            background: url('header_bg.jpg') repeat-x left bottom #f5f5f5;
            padding: 18px 25px;
            margin:0px;
            text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.6);
            color: #666;
        }
        
        #confirmBox h1
        {
            letter-spacing: 0.3px;
            color: #888;
        }
        
        #confirmBox p
        {
            background: none;
            font-size: 16px;
            line-height: 1.4;
            padding-top: 35px;
        }
        
        #confirmButtons
        {
            padding: 15px 0 25px;
            text-align: center;
        }
        
        #confirmBox .button
        {
            display: inline-block;
            background: url('buttons.png') no-repeat;
            color: white;
            position: relative;
            height: 33px;
            font: 17px/33px 'Cuprum' , 'Lucida Sans Unicode' , 'Lucida Grande' , sans-serif;
            margin-right: 15px;
            padding: 0 35px 0 40px;
            text-decoration: none;
            border: none;
        }
        
        #confirmBox .button:last-child
        {
            margin-right: 0;
        }
        
        #confirmBox .button span
        {
            position: absolute;
            top: 0;
            right: -5px;
            background: url('buttons.png') no-repeat;
            width: 5px;
            height: 33px;
        }
        
        #confirmBox .blue
        {
            background-position: left top;
            text-shadow: 1px 1px 0 #5889a2;
        }
        #confirmBox .blue span
        {
            background-position: -195px 0;
        }
        #confirmBox .blue:hover
        {
            background-position: left bottom;
        }
        #confirmBox .blue:hover span
        {
            background-position: -195px bottom;
        }
        
        #confirmBox .gray
        {
            background-position: -200px top;
            text-shadow: 1px 1px 0 #707070;
        }
        #confirmBox .gray span
        {
            background-position: -395px 0;
        }
        #confirmBox .gray:hover
        {
            background-position: -200px bottom;
        }
        #confirmBox .gray:hover span
        {
            background-position: -395px bottom;
        }

js代码:

(function ($) {

    $.confirm = function (params) {

        if ($('#confirmOverlay').length) {
            // A confirm is already shown on the page:
            return false;
        }

        var buttonHTML = '';
        $.each(params.buttons, function (name, obj) {

            // Generating the markup for the buttons:

            buttonHTML += '<a href="#" class="button ' + obj['class'] + '">' + name + '<span></span></a>';

            if (!obj.action) {
                obj.action = function () { };
            }
        });

        var markup = [
			'<div id="confirmOverlay">',
			'<div id="confirmBox">',
			'<h1>', params.title, '</h1>',
			'<p>', params.message, '</p>',
			'<div id="confirmButtons">',
			buttonHTML,
			'</div></div></div>'
		].join('');

        $(markup).hide().appendTo('body').fadeIn();

        var buttons = $('#confirmBox .button'),
			i = 0;

        $.each(params.buttons, function (name, obj) {
            buttons.eq(i++).click(function () {

                // Calling the action attribute when a
                // click occurs, and hiding the confirm.

                obj.action();
                $.confirm.hide();
                return false;
            });
        });
    }

    $.confirm.hide = function () {
        $('#confirmOverlay').fadeOut(function () {
            $(this).remove();
        });
    }

})(jQuery);
$(document).ready(function () {

    $('.delete').click(function () {

        var elem = $(this).closest('.item');

        $.confirm({
            'title': 'Delete Confirmation',
            'message': 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?',
            'buttons': {
                'Yes': {
                    'class': 'blue',
                    'action': function () {
                        elem.slideUp();
                    }
                },
                'No': {
                    'class': 'gray',
                    'action': function () { } // Nothing to do in this case. You can as well omit the action property.
                }
            }
        });

    });

});

HTML代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jquery 信息提示对话框 用CSS3更换一个确认对话框</title>
    <meta name="description" content="jquery信息提示对话框,鼠标点击关闭删除按钮时,点击弹出提示对话框,二次确认用户是否操作该功能。" />
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body>
    <div id="page">

        <div class="item">
            <a href="http://tutorialzine.com/?p=1274">
            	<img src="http://cdn.tutorialzine.com/img/featured/1274.jpg" title="Coding a Rotating Image Slideshow w/ CSS3 and jQuery" alt="Coding a Rotating Image Slideshow w/ CSS3 and jQuery" width="620" height="340" />
            </a>
            <div class="delete">删除</div>
        </div>

</div>
</body>
</html>


用到的图片:

body_bg:
buttons.png:
header_bg.jpg:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小步快跑-

如有帮到您,给个赞赏(^.^)

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值