From c7d6d9e5d67ce79be73142d9b31e5501fde39cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Mon, 31 Jul 2023 12:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20layer=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=20`scrollbar`=20=E5=B1=9E=E6=80=A7=E7=A6=81=E7=94=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=BB=9A=E5=8A=A8=E6=9D=A1=E6=97=B6=EF=BC=8C=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=9C=80=E5=A4=A7=E5=8C=96=E5=86=8D=E8=BF=98=E5=8E=9F?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=BB=9A=E5=8A=A8=E6=9D=A1=E6=9C=AA=E8=83=BD?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/layer.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/modules/layer.js b/src/modules/layer.js index b20e1323..da6b2c90 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -475,7 +475,7 @@ Class.pt.creat = function(){ that.layero = $('#'+ doms[0] + times); that.shadeo = $('#'+ doms.SHADE + times); - config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times); + config.scrollbar || ready.setScrollbar(times); }).auto(times); // 遮罩 @@ -960,13 +960,17 @@ ready.record = function(layero){ layero.attr({area: area}); }; -ready.rescrollbar = function(index){ +// 设置页面滚动条 +ready.setScrollbar = function(index){ + doms.html.css('overflow', 'hidden').attr('layer-full', index); +}; + +// 恢复页面滚动条 +ready.restScrollbar = function(index){ if(doms.html.attr('layer-full') == index){ - if(doms.html[0].style.removeProperty){ - doms.html[0].style.removeProperty('overflow'); - } else { - doms.html[0].style.removeAttribute('overflow'); - } + doms.html[0].style[doms.html[0].style.removeProperty + ? 'removeProperty' + : 'removeAttribute']('overflow'); doms.html.removeAttr('layer-full'); } }; @@ -1097,7 +1101,7 @@ layer.min = function(index, options){ elemMin.hide(); layero.attr('type') === 'page' && layero.find(doms[4]).hide(); - ready.rescrollbar(index); + ready.restScrollbar(index); // 隐藏遮罩 shadeo.hide(); @@ -1109,6 +1113,7 @@ layer.restore = function(index){ var shadeo = $('#'+ doms.SHADE + index); var area = layero.attr('area').split(','); var type = layero.attr('type'); + var options = layero.data('config') || {}; layero.removeData('maxminStatus'); // 移除最大最小状态 @@ -1125,7 +1130,9 @@ layer.restore = function(index){ layero.find('.layui-layer-max').removeClass('layui-layer-maxmin'); layero.find('.layui-layer-min').show(); type === 'page' && layero.find(doms[4]).show(); - ready.rescrollbar(index); + + // 恢复页面滚动条弹层打开时的状态 + options.scrollbar ? ready.restScrollbar(index) : ready.setScrollbar(index); // 恢复遮罩 shadeo.show(); @@ -1144,7 +1151,7 @@ layer.full = function(index){ ready.record(layero); // 记录当前尺寸、坐标 if(!doms.html.attr('layer-full')){ - doms.html.css('overflow','hidden').attr('layer-full', index); + ready.setScrollbar(index); } setTimeout(function(){ @@ -1243,7 +1250,7 @@ layer.close = function(index, callback){ } layer.ie == 6 && ready.reselect(); - ready.rescrollbar(index); + ready.restScrollbar(index); // 记住被关闭层的最小化堆叠坐标 if(typeof layero.attr('minLeft') === 'string'){