Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复scale缩放导致tour错位 #49745 #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/hooks/useTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ export default function useTarget(
};
}, [targetElement, open, updatePos]);

const getBodyDomTransformScaleVal = () => {
const body = document.body;
const style = window.getComputedStyle(body);
const transform = style.getPropertyValue('transform');
const transformOrigin = style.getPropertyValue('transform-origin');
let scale = 1;
if (transform && transform !== 'none' && transformOrigin === '0px 0px') {
const values = transform.split('(')[1].split(')')[0].split(',');
const a = parseFloat(values[0]);
const b = parseFloat(values[1]);
scale = Math.sqrt(a * a + b * b);
}

return scale;
}

// ======================== PosInfo =========================
const mergedPosInfo = useMemo(() => {
if (!posInfo) {
Expand All @@ -84,12 +100,14 @@ export default function useTarget(
const gapOffsetY = getGapOffset(1);
const gapRadius = gap?.radius || 2;

const bodyScaleRadio = getBodyDomTransformScaleVal();

return {
left: posInfo.left - gapOffsetX,
top: posInfo.top - gapOffsetY,
width: posInfo.width + gapOffsetX * 2,
height: posInfo.height + gapOffsetY * 2,
radius: gapRadius,
left: (posInfo.left - gapOffsetX) / bodyScaleRadio,
top: (posInfo.top - gapOffsetY) / bodyScaleRadio,
width: (posInfo.width + gapOffsetX * 2) / bodyScaleRadio,
height: (posInfo.height + gapOffsetY * 2) / bodyScaleRadio,
radius: gapRadius / bodyScaleRadio,
};
}, [posInfo, gap]);

Expand Down