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 + }; + }, }); })();