boxDialog 是一款轻量级的弹窗通用组件,包括弹出字符串内容、自定义 DOM 结构等以及快捷操作等功能,具有高度的可定制性。
该弹窗组件不依赖于任何第三方库,原生JS ES6 语法编写,支持到IE8+。
调用主函数 boxDialog.open()
, 传入相关参数.
boxDialog.open({
title:'成功icon',
content:'提交成功',
shade: {
opacity: 0.9
},
size:['450px'],
button: {
ok: {
callback:function(){}
}
},
icon: 'success'
});
boxDialog.open({
title:'自定义内容1',
content: document.getElementById('content1'),
size:['400px']
});
boxDialog.open({
title:'成功icon',
content:'提交成功',
shade: {
opacity: 0.9
},
size:['450px','300px'],
button: {
ok: {
text: '确定', // 按钮文本 '确定', 默认
className: 'active',
callback: null // {function} 点击确定按钮执行的回调函数.
},
cancel: {
text: '取消', // 按钮文本 '取消', 默认
className: null,
callback: null // {function} 点击取消按钮执行的回调函数.
}/*,
varBtn3: {
text: '按钮3', // 自定义 button
className: null,
callback: null
}*/
},
icon: 'success'
});
//可使用的参数
const config = {
type: 'dialog', //默认普通对话框
title: '\u6d88\u606f', // 标题, 默认'消息'.
content: '欢迎使用boxDialog弹窗组件!', // 弹窗主内容.
size: ['20px', '10px'], // 内容宽、高
showClose: true, // 弹窗的右上角关闭按钮是否显示,默认显示.
className: null, // {string} 自定义弹窗最外层class.
padding: '20px', //主内容区默认内边距
icon: null, // 图标名称,字符串,如: icon:'success'.
time: null, // 自动关闭时间, 单位秒.
fixed: true, // 是否固定位置, 默认true固定位置.
zIndex: 20150326, // 弹窗的堆叠顺序.
drag: false, // 拖拽开关, 默认关闭.
resize: true, // 窗口改变, 调整弹窗位置.
position: null, // X,Y轴坐标,不设置默认居中,设置如:{left:'100px',top:'100px'},4个参数分别表示位置:左,上,右,下,原理取于css语法的left、top、right、bottom.
shade: { // 遮罩层默认显示, 设置shade:false, 不显示遮罩.
background: '#000', // 遮罩层背景色, 默认黑色.
opacity: 0.8, // 遮罩层透明度, 默认0.8.
},
button: {
ok: {
text: '确定', // 按钮文本 '确定', 默认
className: 'active',
callback: null // {function} 点击确定按钮执行的回调函数.
},
cancel: {
text: '取消', // 按钮文本 '取消', 默认
className: null,
callback: null // {function} 点击取消按钮执行的回调函数.
}/*,
varBtn3: {
text: '按钮3', // 自定义 button
className: null,
callback: null
}*/
},
init: null, // {function} 初始化成功执行的回调函数.
close: null // {function} 弹窗关闭执行的回调函数.
};
callback: function(index){
//index就是该弹窗索引
}
boxDialog = {
open: dialog,
close: close,
closeAll: closeAll,
msg: msg,
alert: alert,
list: list,
version: version
};
msg: msg 弹出快捷信息提示,使用方法:boxDialog.msg(title,content,icon,sec), 参数都可选; 如:boxDialog.msg( '提交成功','提交成功 1s 后消失','success',1 );
alert: alert 模拟原生的alert效果,使用方法:boxDialog.alert(content,callback,w), 参数都可选; 如: boxDialog.alert('提交成功');
seajs.config({
base: './js/',
alias: {
'boxDialog':'../../lib/dist/boxDialog.min'
}
});
seajs.use(['jquery', 'modules/main'], function($,ex){
$('#abc').on('click', function(){
ex.boxDialog.alert('abc');
});
});
define(function(require,exports,module){
var boxDialog = require('boxDialog');
exports.boxDialog = boxDialog;
})
boxDialog 将持续更新,优化其性能和体验,谢谢关注。
V1.0
Copyright (c) 2015 Licensed under the MIT license.