Dcat-admin框架下重新写的弹窗样式,实现设置固定最大高度弹窗滚动,实现更好的页面效果。
public function layer(){
return <<<JS
//设置高度
function resizeHeight(layero,height = 0){
var iframe = layero.find('iframe');
var parent_height = parent.document.body.clientHeight;
if(height != 0){
parent_height = parent_height * 0.6;
}
var iframe_height = parent_height-20;
layero.css({
'max-height' : parent_height+'px',
'min-height' : '450px',
'overflow' : 'hidden',
});
$(iframe).css({
'max-height' : iframe_height+'px',
'min-height' : '420px',
'overflow' : 'auto',
});
}
//设置标题
function layerTitle(layero,is_min = false){
if(is_min){
layero.find('h4.self_layer_title').css({
'font-size' : '1rem',
'margin-top' : '17px'
});
}
else{
layero.find('h4.self_layer_title').css({
'font-size' : '1.32rem',
'margin-top' : '14px'
});
}
}
$('.layer_btn').on('click',function() {
var url = $(this).data('url');
var title = $(this).data('title');
layer.open({
type: 2 //Page层类型
,offset:'35px'
,area: ['875px', 'auto']//max-height:840px;
,title: '<h4 class="self_layer_title">'+title+'</h4>'
,shade: 0.3 //遮罩透明度
,maxmin: true //允许全屏最小化
,anim: 1 //0-6的动画形式,-1不开启
,content: [url,'yes']
,success:function(layero,index){
layer.iframeAuto(index);
var body = parent.$('body');
body.css('overflow','hidden');
$(parent.document).scrollHeight = '100%';
layerTitle(layero);
resizeHeight(layero,820);
}
,end:function() {
parent.$('body').css('overflow','auto');
}
,full: function(layero) {
layerTitle(layero);
resizeHeight(layero,820);
layero.find('.layui-layer-content').css('height','100%');
layero.find('iframe').css('height','100%');
}
,restore: function(layero) {
layerTitle(layero);
resizeHeight(layero,820);
}
,min: function(layero) {
layerTitle(layero,true);
}
,shadeClose:true
});
});
JS;
}
Admin::script(layer()); //引入js
//设置触发器
'<span class="layer_btn" data-url="" data-title=""> btn</span>';
如果不生效在success中加入
layer.getChildFrame('body', index).css('overflow-x','hidden');