Skip to content

Commit cc19d27

Browse files
committed
Add page offset to pointer position #22
1 parent 9f1db6e commit cc19d27

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/PieMenu.component.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ const PieMenu = ({
6363

6464
const isInsidePie = (x, y) => {
6565
if (!ref.current) return false;
66+
const { pageXOffset, pageYOffset } = window;
6667
const { left: pieX, top: pieY } = ref.current.getBoundingClientRect();
67-
const distance = (x - (pieX - window.pageXOffset) - radiusPx) ** 2
68-
+ (y - (pieY + window.pageYOffset) - radiusPx) ** 2;
68+
const distance = (x + pageXOffset - (pieX + pageXOffset) - radiusPx) ** 2
69+
+ (y + pageYOffset - (pieY + pageYOffset) - radiusPx) ** 2;
6970
return centerArea <= distance && distance <= pieArea;
7071
};
7172

0 commit comments

Comments
 (0)