From eedd76cacbac6f3a46015db7fac5fd811ca64ee3 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Fri, 13 Mar 2020 15:11:34 +0800 Subject: [PATCH] =?UTF-8?q?scale=20=E5=8C=BA=E5=88=86=20x=20y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/dom.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/dom.tsx b/src/utils/dom.tsx index b8c5dabf..6049a398 100644 --- a/src/utils/dom.tsx +++ b/src/utils/dom.tsx @@ -150,7 +150,8 @@ export function calculatePosition( : getPosition(target, container); const {height: overlayHeight, width: overlayWidth} = getOffset(overlayNode); const clip = overlayNode.getBoundingClientRect(); - const scale = clip.width / overlayNode.offsetWidth; + const scaleX = clip.width / overlayNode.offsetWidth; + const scaleY = clip.width / overlayNode.offsetWidth; // auto 尝试四个方向对齐。 placement = @@ -198,8 +199,8 @@ export function calculatePosition( // 如果还有其他可选项,则做位置判断,是否在可视区域,不完全在则继续看其他定位情况。 if (tests.length) { const transformed = { - x: clip.x + positionLeft / scale, - y: clip.y + positionTop / scale, + x: clip.x + positionLeft / scaleX, + y: clip.y + positionTop / scaleY, width: overlayWidth, height: overlayHeight }; @@ -268,10 +269,10 @@ export function calculatePosition( } return { - positionLeft: positionLeft / scale, - positionTop: positionTop / scale, - arrowOffsetLeft: arrowOffsetLeft / scale, - arrowOffsetTop: arrowOffsetTop / scale, + positionLeft: positionLeft / scaleX, + positionTop: positionTop / scaleY, + arrowOffsetLeft: arrowOffsetLeft / scaleX, + arrowOffsetTop: arrowOffsetTop / scaleY, activePlacement }; }