不爱废话,直接贴代码
CSS :(主要弹出框css)
/*弹出层*/.modal{ position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1050; display: none; overflow: hidden; -webkit-overflow-scrolling: touch; outline: 0; background-color: rgba(0, 0, 0, 0.5);}.modal .modal-dialog{ position: relative; width:auto; margin: 10px;}.modal .modal-content{ position: relative; background-color: #fff; -webkit-background-clip: padding-box; background-clip: padding-box; border: 1px solid #999; border: 1px solid rgba(0, 0, 0, .2); border-radius: 6px; outline: 0; -webkit-box-shadow: 0 3px 9px rgba(0, 0, 0, .5); box-shadow: 0 3px 9px rgba(0, 0, 0, .5); max-width: 350px; min-width: 300px; margin: 0 auto; display: block;}.modal .modal-header{ padding: 15px; border-bottom: 1px solid #e5e5e5;}.modal .modal-header h3{ margin: 0; text-align: center;}.modal .modalclose{ position: absolute; right: -10px; top: -12px;}.modal .modalclose i{ color:#FE9900; font-size: 40px;}.modal .modal-body{ position: relative; padding: 15px;}.modal .modal-footer { /*padding: 10px;*/ text-align: right; border-top: 1px solid #e5e5e5; text-align: center;}.modal .modal-footer button{ margin: 10px;}
js:
/* *弹出框调用 Modal.alert({msg:'111'}) Modal.confirm({msg:'111'},function(is){console.log(is)}) **/var dialog_model = ''document.write(dialog_model)var alr = $("#dialogModal");var windHeight = $(window).height();alr.children().css({ "top":(windHeight/2)-165, "right": "15px",}) var ahtml = alr.html();var Modal = { alert:function(options){ alr.html(ahtml); this._dialog(options); alr.fadeIn() alr.find('.cancel').hide(); alr.find('.ok').off('click').on('click',function() { alr.fadeOut() }); }, confirm:function(options,callback) { alr.html(ahtml); this._dialog(options); alr.fadeIn() alr.find('.cancel').show(); alr.find('.ok').off('click').on('click',function() { callback && callback(true); }); alr.find('.cancel').off('click').on('click',function() { alr.fadeOut(); }) }, _dialog:function(options){ var reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm'); alr.html(ahtml); var ops = { msg: "数据出错", title: "操作提示", btnok: "确定", btncl: "取消" } $.extend(ops, options); var html = alr.html().replace(reg, function(node, key) { return { Title: ops.title, Message: ops.msg, BtnOk: ops.btnok, BtnCancel: ops.btncl }[key]; }); alr.html(html); }}
(原创)