Skip to content

Commit

Permalink
Add page offset to pointer position #22
Browse files Browse the repository at this point in the history
  • Loading branch information
psychobolt committed Sep 12, 2021
1 parent 9f1db6e commit cc19d27
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/PieMenu.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ const PieMenu = ({

const isInsidePie = (x, y) => {
if (!ref.current) return false;
const { pageXOffset, pageYOffset } = window;
const { left: pieX, top: pieY } = ref.current.getBoundingClientRect();
const distance = (x - (pieX - window.pageXOffset) - radiusPx) ** 2
+ (y - (pieY + window.pageYOffset) - radiusPx) ** 2;
const distance = (x + pageXOffset - (pieX + pageXOffset) - radiusPx) ** 2
+ (y + pageYOffset - (pieY + pageYOffset) - radiusPx) ** 2;
return centerArea <= distance && distance <= pieArea;
};

Expand Down

0 comments on commit cc19d27

Please sign in to comment.