From 41971746e8ec075696585baa997ad5937553d662 Mon Sep 17 00:00:00 2001 From: moecasts Date: Thu, 5 Dec 2024 11:27:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20getPosition=20mouse=20=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=85=81=E8=AE=B8=E5=8A=A0=E4=B8=8A=20clientY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/utils/getPosition.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/js/utils/getPosition.ts b/js/utils/getPosition.ts index 06a92a1ea7..9313425e19 100644 --- a/js/utils/getPosition.ts +++ b/js/utils/getPosition.ts @@ -5,6 +5,7 @@ const getPosition = ( contentEle: HTMLElement, placement: Partial, clientX?: Number, + clientY?: Number, ): { left: number; top: number } => { const targetRect = targetEle.getBoundingClientRect() as DOMRect; const contentRect = contentEle.getBoundingClientRect() as DOMRect; @@ -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; // 后续有需要可以再扩展 } @@ -56,4 +59,4 @@ const getPosition = ( return position; }; -export default getPosition; +export default getPosition; \ No newline at end of file