add get mouse position function

This commit is contained in:
DefectingCat
2022-10-10 09:16:03 +08:00
parent d5604e4b2e
commit 3f6b7f0825
3 changed files with 25 additions and 35 deletions

View File

@ -85,3 +85,15 @@ export const generateToc = (source: string) => {
return toc;
};
export const getMousePosition = (e: MouseEvent | globalThis.TouchEvent) => {
return e instanceof MouseEvent
? {
x: e.clientX,
y: e.clientY,
}
: {
x: e.touches[0].clientX,
y: e.touches[0].clientY,
};
};