scale 区分 x y

This commit is contained in:
2betop 2020-03-13 15:11:34 +08:00
parent 5ac7061815
commit eedd76cacb
1 changed files with 8 additions and 7 deletions

View File

@ -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
};
}