Skip to content

Commit

Permalink
feat(utils): getPosition mouse 计算允许加上 clientY
Browse files Browse the repository at this point in the history
  • Loading branch information
moecasts committed Dec 5, 2024
1 parent 94e21e2 commit 4197174
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions js/utils/getPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const getPosition = (
contentEle: HTMLElement,
placement: Partial<Placement>,
clientX?: Number,
clientY?: Number,
): { left: number; top: number } => {
const targetRect = targetEle.getBoundingClientRect() as DOMRect;
const contentRect = contentEle.getBoundingClientRect() as DOMRect;
Expand All @@ -28,7 +29,9 @@ const getPosition = (
break;
case 'mouse':
position.left += Number(clientX);
position.top += targetRect.top + targetRect.height + 8;
position.top += typeof clientY !== 'undefined'
? Number(clientY) + 16
: targetRect.top + targetRect.height + 8;
break;
// 后续有需要可以再扩展
}
Expand Down Expand Up @@ -56,4 +59,4 @@ const getPosition = (
return position;
};

export default getPosition;
export default getPosition;

Check failure on line 62 in js/utils/getPosition.ts

View workflow job for this annotation

GitHub Actions / test

Newline required at end of file but not found

0 comments on commit 4197174

Please sign in to comment.