弹出对话框插件MiniDialog(原创)

所属分类:UI-对话框,弹出层,工具提示

 26973  286  查看评论 (44)
分享到微信朋友圈
X
弹出对话框插件MiniDialog(原创) ie兼容10

更新时间:2019/6/21 上午11:36:35

更新说明:

新增 okNotClose 方法用来针对信息展示类对话框点击确定按钮时阻止对话框关闭;

新增 waiting 效果的对话框。


MiniDialog 对话框

功能丰富、使用简单、灵活多样、体积轻巧的无任何第三方依赖的 JavaScript 对话框组件。

源代码说明:

MiniDialog 的原始开发版程序采用基于 es6 标准的 JavaScript 编写,如果需要兼容 IE11 浏览器,需要将其转换成 es5 格式,作者已提供了经过 Babel 转换之后的程序,请前往 dist 目录下查看,该目录下的三个文件分别是基于 es6 的原始未压缩版以及转换成 es5 格式的未压缩和已压缩版,请根据实际需求选择使用。

代码示例:

  1. 四种信息提示对话框

  2. 快捷方式

  3. 常规配置

  4. 自定义内容背景色

  5. 可拖动的对话框

  6. 全屏对话框

  7. 自动关闭

  8. 嵌入Iframe

  9. 嵌入图片

  10. 嵌入多张图片

  11. 嵌入视频

  12. 确定按钮-加载中

  13. 按钮事件

  14. 开关事件

四种信息提示对话框

// 内容可选
Dialog.info( "标题", "内容" );
Dialog.success( "标题", "内容" );
Dialog.warn( "标题", "内容" );
Dialog.error( "标题", "内容" );
// 还可支持确定回调,如:
Dialog.info( "标题", "内容" ).ok(function () {
    alert( "确定" );    
})

快捷方式

// 只传入内容(此时将采用默认标题:网页消息)
Dialog( "内容" );
// 传入标题和内容
Dialog( "标题", "内容" );
// 传入标题、内容和对话框宽度(单位:px)
Dialog( "标题", "内容", 800 );

常规配置

Dialog({
    title: "标题",
    content: "内容",
    width: 800
});

自定义内容背景色

Dialog({
    title: "标题",
    content: "内容",
    width: 800
});

可拖动的对话框

Dialog({
    title: "标题",
    content: "内容",
    draggable: true
});

全屏对话框

Dialog({
    title: "标题",
    content: "内容",
    fullscreen: true
});

自动关闭

Dialog({
    title: "标题",
    content: "内容",
    autoClose: 5000
});

嵌入 Iframe

// iframeContent 中的 src 和 height 属性必须要设置
Dialog({
    title: "标题",
    width: 1100,
    iframeContent: {
        src: "http://www.baidu.com/",
        height: 600
    },
    showButton: false
});

嵌入图片

// imageContent 中的 src 和 height 属性必须要设置
Dialog({
    width: 1100,
    imageContent: {
        src: "demo.png",
        height: 600
    },
    showButton: false,
    showTitle: false,
    maskClose: true
});

嵌入多张图片

// imageContent 中的 src 和 height 属性必须要设置
Dialog({
    width: 700,
    imageContent: {
        src: [ "1.png", "2.png", "3.png", "4.png", "5.png" ],
        height: 400
    },
    showButton: false,
    showTitle: false,
    maskClose: true
});

嵌入视频

// videoContent 中的 src 和 height 属性必须要设置
Dialog({
    width: 800,
    videoContent: {
        src: "demo.mp4",
        height: 450
    },
    showButton: false,
    showTitle: false,
    maskClose: true
});

确定按钮-加载中

Dialog({
    title: "标题",
    content: "内容",
    ok: {
        loading: true,
        loadingText: "等一会",
        callback: function () {
            setTimeout(function () {
                Dialog.close();
            }, 3000)
        }
    }
});

按钮事件

Dialog({
    title: "标题",
    content: "内容",
    ok: {
        callback: function () {
            alert( "确定" );
        }
    },
    cancel: {
        callback: function () {
            alert( "取消" );
        }
    }
});

开关事件

Dialog({
    title: "标题",
    content: "内容",
    afterOpen: function () {
        alert( "打开了对话框" );
    },
    afterClose: function () {
        alert( "关闭了对话框" );
    }
});

全部属性及默认值:

/* 
 * 以下配置项只适用于通过 Dialog({}) 形式调用的对话框,
 * 不能用于 info / success / warn / error 这四种信息提示对话框上
 */
Dialog({
    title: "网页消息",               // 对话框标题(纯文本格式)
    content: "",                    // 对话框内容(可传入 HTML 结构)
    contentBgColor: "#fff",         // 内容区域的背景色
    iframeContent: null,            // 嵌入 iframe 的配置项,有两个必填属性 { src, height }
    videoContent: null,             // 嵌入图片的配置项,有两个必填属性 { src, height }
    imageContent: null,             // 嵌入视频的配置项,有两个必属性 { src, height },一个可选属性 { autoplay: true/false }
    fullscreen: false,              // 全屏显示
    draggable: false,               // 可以拖动(设置此属性后,遮罩层将自动隐藏)
    maskClose: false,               // 点击遮罩层关闭对话框
    mask: true,                     // 显示遮罩层
    closable: true,                 // 显示右上角关闭图标
    bodyScroll: true,               // body 可以滚动
    showTitle: true,                // 显示标题
    showButton: true,               // 显示按钮
    autoCloseEffect: true,          // 当设置了自动关闭时,显示自动关闭的动画效果
    autoClose: 0,                   // 自动关闭的时长,单位:ms(默认:0 表示不开启自动关闭功能)
    parentsIframeLayer: 0,          // 在祖先级 iframe 中创建对话框,数字表示祖先 iframe 的级数
    borderRadius: 6,                // 对话框圆角值,单位:px
    width: 500,                     // 对话框宽度,单位:px
    ok: {
        text: "确定",                // 确定按钮的文字
        loading: false,             // 点击确定按钮时,是否显示 loading 效果(此时将不会执行关闭对话框的操作)
        loadingText: "确定",         // 显示 loading 效果时,确定按钮文字的变化
        notClose: false,            // 点击确定按钮是否关闭对话框
        callback: function () {}    // 点击确定按钮的回调函数
    },
    cancel: {
        text: "取消",                // 取消按钮的文字
        show: true,                 // 是否显示取消按钮
        callback: function () {}    // 点击取消按钮的回调函数
    },
    afterOpen: function () {},      // 对话框打开后的回调函数
    afterClose: function () {}      // 对话框关闭后的回调函数
});

全局关闭方法:

// 关闭指定对话框
var thisDialog = Dialog( "标题" );
Dialog.close( thisDialog );
// 关闭全部对话框
Dialog.close();
相关插件-对话框,弹出层,工具提示

讨论这个项目(44)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    li-xyz 0
    2021/11/23 3:21:15
    您好,在嵌入视频时,点击播放,会自动请求服务器的视频连接,但是关闭 Dialog 之后,还会继续请求,有没有办法在关闭 Dialog 的时候中断请求啊
    回复
    淡淡的梦 0
    2021/2/28 21:17:00

    能不能以对象的方式调用对话框
    类似于这样:

    var demo = new Dialog({
        title: "标题",
        content: "内容"
    });
    //打开弹窗
    demo.open();
    //关闭弹窗
    demo.colose();
    回复
    记忆ツ半存、 0
    2021/1/28 11:03:48
    含iframe的弹出层,能否跳出本页面,到最外层页面?如果能实现,是否可以添加id加以区分?
    回复
    记忆ツ半存、 0
    2021/1/28 10:56:54
    你好,有没有压缩过的js吗
        西瓜0
        2021/1/28 11:15:25

        用js格式化工具自己压一下就行了

        https://www.jq22.com/jsgsh
    回复
    帽子踌躇 0
    2020/9/1 9:15:37
    想问下,这个插件如何兼容ie9浏览器 回复
    你过得可好 0
    2019/12/23 13:27:00
    【四种信息提示对话框】不支持手机客户端页面怎么解决?在控制台模拟手机触发js报错,在pc正常 回复
    qq694201656 0
    2019/11/12 17:10:03
    看了你的源码,貌似有高度判断然后自己适应,但是好像没有起作用 回复
    qq694201656 0
    2019/11/12 16:30:12
    普通弹窗怎么设置高度呢?,内容多了之后无法滚动
        qq6942016560
        2019/11/12 16:39:10
        希望普通弹窗可以设置高度,这样内容超过高度的部分可以上下滚动,谢谢,插件很好
    回复
    丢丢熊 0
    2019/8/12 11:35:00
    提交表单的时候 怎么在 验证表单成功后再 执行带loading的按钮事件,也就是 ok
        星空1
        2019/8/12 11:59:39
        您好,目前暂无直接的方法处理您的需求,现在的ok事件和loading效果是直接跟按钮绑定的
    回复
    Promising 0
    2019/7/29 23:45:41
    请问一下,我想往frame里传递参数,有没有这个操作?
        星空0
        2019/7/30 0:07:01
        您好,感谢您的反馈。目前暂无向 中传递参数的功能。
    回复
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复