使用jquery-confirm优化JS弹出框

jquery-confirm是一款可整合font-awesome,bootstrap一起使用的强大jQuery对话框和确认框插件

Demo演示地址:http://karle.vip/jc.html

css依赖

<link href="https://cdn.bootcss.com/jquery-confirm/3.2.3/jquery-confirm.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">

js依赖

<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js "></script>
<script src="https://cdn.bootcss.com/jquery-confirm/3.2.3/jquery-confirm.min.js "></script>
<script src="https://cdn.bootcss.com/jquery.form/4.2.1/jquery.form.js"></script>

demo1(消息提示框)

function confirm_alert(msg) {
    $.alert({
        title: '系统提示',
        content: msg,
        icon: 'fa fa-comment',
        type: 'green',
        buttons: {
            "是的": function() {

            }
        }
    });
}

demo1


demo2(消息提示框+倒计时操作)

function confirm_alert_ok_goto_dj(msg, url) {
    $.alert({
        title: '系统提示',
        content: msg,
        icon: 'fa fa-comment',
        type: 'green',
        autoClose: '好的|3000',
        escapeKey: '好的',
        buttons: {
            "好的": {
                btnClass: 'btn-blue',
                action: function() {
                    window.location.href = url;
                }
            }
        }
    });
}

demo3


demo3(弹出框接收输入参数,Ajax提交)

function ajax_submit(id) {
    $.confirm({
        icon: 'fa fa-plus',
        type: 'blue',
        title: '添加数据',
        content: '<div class="form-group"><input type="text" placeholder="请输入名称" class="param_name form-control" /></div>' +
            '<div class="form-group"><input type="text" placeholder="请输入年龄" class="param_age form-control"/></div>',
        buttons: {
            '取消': function() {},
            '添加': {
                btnClass: 'btn-blue',
                action: function() {
                    var param_age = this.$content.find('.param_age').val();
                    var param_name = this.$content.find('.param_name').val();
                    confirm_alert("你提交的数据:id:" + id + ",名称:" + param_name + ",年龄:" + param_age);
                    /*//此处可写Ajax请求
                    $.get(url, {
                            name: param_name,
                            id: id,
                            age: param_age
                        },
                        function(result) {
                            //处理结果
                        });*/
                }
            }
        }
    });
}

demo3

更多示例请查看Demo,源码下载(3分):http://download.csdn.net/download/qq_19260029/9972236

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,我可以为你提供一个示例代码,使用 jquery-confirm 插件实现弹出缩小后出现在右侧边缘,恢复后出现在中间区域。 首先,你需要引入 jquery-confirm 插件jQuery 库。然后,使用以下代码创建一个弹出: ```html <div id="my-confirm" class="my-confirm"> <h4>提示</h4> <p>这是一个弹出</p> </div> ``` 接下来,你可以使用以下 JavaScript 代码初始化 jquery-confirm 插件,并设置弹出缩小和恢复的回调函数: ```javascript $(document).ready(function() { // 初始化 jquery-confirm 插件 $.confirm({ title: '', content: $('#my-confirm'), columnClass: 'medium', draggable: true, dragWindowGap: 0, onContentReady: function() { var self = this; this.$content.find('.btn-minimize').click(function() { // 缩小弹出 self.$content.parent().removeClass('medium').addClass('small'); self.$content.parent().css({ top: $(window).height() - self.$content.parent().outerHeight() - 50, left: $(window).width() - self.$content.parent().outerWidth() - 50 }); }); this.$content.find('.btn-maximize').click(function() { // 恢复弹出 self.$content.parent().removeClass('small').addClass('medium'); self.$content.parent().css({ top: ($(window).height() - self.$content.parent().outerHeight()) / 2, left: ($(window).width() - self.$content.parent().outerWidth()) / 2 }); }); } }); }); ``` 在这个示例中,我们首先初始化了 jquery-confirm 插件,并使用 content 属性指定了弹出的内容。然后设置 draggable 属性为 true,允许用户拖动弹出。同时设置 dragWindowGap 属性为 0,使弹出拖动时与鼠标指针对齐。 接着,我们在 onContentReady 回调函数中获取弹出的按钮元素,并为按钮元素绑定了 click 事件。在缩小按钮的 click 事件中,我们使用 jQuery 的 css() 方法设置了弹出的位置,使其出现在右侧边缘。在恢复按钮的 click 事件中,我们同样使用 css() 方法设置了弹出的位置,使其出现在中间区域。 最后,我们在 HTML 中为弹出添加了两个按钮,分别是缩小和恢复按钮: ```html <button class="btn-minimize">缩小</button> <button class="btn-maximize">恢复</button> ``` 希望这个示例代码能够帮助你实现弹出缩小后出现在右侧边缘,恢复后出现在中间区域的效果。如果还有其他问题,欢迎继续提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值