/** * Created by Administrator on 2017/6/21. */ var index; /*弹出层*/ /* 参数解释:弹出页面 title 标题 url 请求的url id 需要操作的数据id w 弹出层宽度(缺省调默认值) h 弹出层高度(缺省调默认值) */ function layer_show(title,url,w,h){ if (title == null || title == '') { title=false; } if (url == null || url == '') { url="404.html"; } if (w == null || w == '') { w=800; } if (h == null || h == '') { h=($(window).height() - 50); } layer.open({ type: 2, area: [w+'px', h +'px'], fix: false, //不固定 shade:0.4, title: title, content: url }); } /** * 弹出最大化 * @param title * @param url * @param w * @param h */ function layer_showMax(title,url,w,h){ if (title == null || title == '') { title=false; } if (url == null || url == '') { url="404.html"; } if (w == null || w == '') { w=800; } if (h == null || h == '') { h=($(window).height() - 50); } index = layer.open({ type: 2, area: [w+'px', h +'px'], fix: false, //不固定 shade:0.4, title: title, content: url }); layer.full(index); } /** * 弹出页面 没有关闭功能 * @param title * @param url * @param w * @param h */ function layer_showNoCloseBtn(title,url,w,h){ if (title == null || title == '') { title=false; } if (url == null || url == '') { url="404.html"; } if (w == null || w == '') { w=800; } if (h == null || h == '') { h=($(window).height() - 50); } layer.open({ type: 2, area: [w+'px', h +'px'], fix: false, //不固定 closeBtn: 0, shade:0.4, title: title, content: url }); } /** * 弹出div * @param title * @param id * @param w * @param h */ function layer_showView(title,id,w,h){ if (title == null || title == '') { title=false; } if (w == null || w == '') { w=800; } if (h == null || h == '') { h=($(window).height() - 50); } index = layer.open({ type: 1, area: [w+'px', h +'px'], fix: false, //不固定 shade:0.4, title: title, content: $('#' + id + '') //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 }); } /** * 弹出div 没有关闭功能 * @param title * @param id * @param w * @param h */ function layer_showViewNoCloseBtn(title,id,w,h){ if (title == null || title == '') { title=false; } if (w == null || w == '') { w=800; } if (h == null || h == '') { h=($(window).height() - 50); } index = layer.open({ type: 1, area: [w+'px', h +'px'], fix: false, //不固定 closeBtn: 0, shade:0.4, title: title, content: $('#' + id + '') //这里content是一个DOM,注意:最好该元素要存放在body最外层,否则可能被其它的相对元素所影响 }); } /** * 关闭弹出框口 页面的 */ function layer_close(){ var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); } /*关闭弹出框口 div的*/ function layer_closeView() { //var index = parent.layer.getFrameIndex(window.name); //parent.layer.close(index); //console.log(index); layer.close(index); } //提示框 function opaler(){ layer.msg('操作成功!',{icon:1,time:1000},function(index){ layer_close(); }); } //提示框 function opalerNO(){ layer.msg('操作失败!',{icon:2,time:1000},function(index){ layer_close(); }); } //提示框 function opalerView(){ layer.msg('操作成功!',{icon:1,time:1000},function(index){ layer_closeView(); }); } //提示框 function opalerViewNO(){ layer.msg('操作失败!',{icon:2,time:1000},function(index){ layer_closeView(); }); } //alert 框 $.fn.modalAlert = function (content, type) { var icon = ""; var iconType = 0; if (type == 'success') { icon = "fa-check-circle"; iconType = 1; } if (type == 'error') { icon = "fa-times-circle"; iconType = 2; } if (type == 'warning') { icon = "fa-exclamation-circle"; iconType = 3; } top.layer.alert(content, { icon: iconType, title: "系统提示", btn: ['确认'], btnclass: ['btn btn-primary'], }); }; // msg 消息 $.fn.modalMsg = function (content, type) { var iconType = 0; if (type != undefined) { var icon = ""; if (type == 'success') { icon = "fa-check-circle"; iconType = 1; } if (type == 'error') { icon = "fa-times-circle"; iconType = 2; } if (type == 'warning') { icon = "fa-exclamation-circle"; iconType = 3; } top.layer.msg(content, { icon: iconType, time: 4000, shift: 5 }); top.$(".layui-layer-msg").find('i.' + iconType).parents('.layui-layer-msg').addClass('layui-layer-msg-' + type); } else { top.layer.msg(content); } }; //确认框 $.fn.modalConfirm = function (content, callBack) { layer.confirm(content, { icon: 3, title: "系统提示", btn: ['确认', '取消'], btnclass: ['btn btn-primary', 'btn btn-danger'], }, function (index) { callBack(); layer.close(index); }); };
layer 封装
猜你喜欢
转载自blog.csdn.net/qq_33842795/article/details/80227793
今日推荐
周排行