From aab95e8e2a65a41c206ecc068b87a868a9769dad Mon Sep 17 00:00:00 2001 From: zsmj Date: Wed, 14 Dec 2022 15:22:32 +0800 Subject: [PATCH] =?UTF-8?q?BI-118917=20fix:=20bi.switcher=E8=BF=99?= =?UTF-8?q?=E7=A7=8D=E5=88=A9=E7=94=A8Masker=E9=81=AE=E7=BD=A9=E7=9A=84?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/controller/controller.layer.js | 61 +++++++++++++++---------- src/core/platform/web/dom.js | 14 ++++++ 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/core/controller/controller.layer.js b/src/core/controller/controller.layer.js index 6887603f7..abc2d7f0e 100644 --- a/src/core/controller/controller.layer.js +++ b/src/core/controller/controller.layer.js @@ -63,41 +63,54 @@ BI.LayerController = BI.inherit(BI.Controller, { var layout = BI.createWidget({ type: "bi.absolute", invisible: true, - items: [{ - el: widget, - left: 0, - right: 0, - top: 0, - bottom: 0 - }] + items: [ + { + el: widget, + left: 0, + right: 0, + top: 0, + bottom: 0 + } + ] }, context); BI.createWidget({ type: "bi.absolute", element: op.container || this.options.render, - items: [{ - el: layout, - left: offset.left || 0, - right: offset.right || 0, - top: offset.top || 0, - bottom: offset.bottom || 0 - }] + items: [ + { + el: layout, + left: offset.left || 0, + right: offset.right || 0, + top: offset.top || 0, + bottom: offset.bottom || 0 + } + ] }); if (w) { layout.element.addClass("bi-popup-view"); - layout.element.css({ - left: w.offset().left + (offset.left || 0), - top: w.offset().top + (offset.top || 0), - width: offset.width || (w.outerWidth() - (offset.left || 0) - (offset.right || 0)) || "", - height: offset.height || (w.outerHeight() - (offset.top || 0) - (offset.bottom || 0)) || "" - }); - layout.element.on("__resize__", function () { - w.is(":visible") && - layout.element.css({ + + function getComputedPosition() { + + var css = { left: w.offset().left + (offset.left || 0), top: w.offset().top + (offset.top || 0), width: offset.width || (w.outerWidth() - (offset.left || 0) - (offset.right || 0)) || "", height: offset.height || (w.outerHeight() - (offset.top || 0) - (offset.bottom || 0)) || "" - }); + }; + + const { top, left, scaleY, scaleX } = BI.DOM.getPositionRelativeContainingBlockRect(layout.element[0]); + + css.top = (css.top - top) / scaleY; + css.left = (css.left - left) / scaleX; + + return css; + } + + + layout.element.css(getComputedPosition()); + layout.element.on("__resize__", function () { + w.is(":visible") && + layout.element.css(getComputedPosition()); }); } this.add(name, widget, layout); diff --git a/src/core/platform/web/dom.js b/src/core/platform/web/dom.js index 203683297..d2fffd753 100644 --- a/src/core/platform/web/dom.js +++ b/src/core/platform/web/dom.js @@ -732,5 +732,19 @@ return BI.DOM.getPositionRelativeContainingBlock(element.parentNode); }, + + /** + * 获取position:fixed相对定位的元素的clientRect + */ + getPositionRelativeContainingBlockRect: function (element) { + var positionRelativeElement = BI.DOM.getPositionRelativeContainingBlock(element); + var rect = positionRelativeElement.getBoundingClientRect(); + + return { + ...rect.toJSON(), + scaleX: rect.width / positionRelativeElement.offsetWidth, + scaleY: rect.height / positionRelativeElement.offsetHeight + }; + }, }); })();