Skip to content

Commit

Permalink
Support window offset #22
Browse files Browse the repository at this point in the history
  • Loading branch information
psychobolt committed Aug 27, 2021
1 parent d29d0f3 commit 5809034
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/PieMenu.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const PieMenu = ({
const isInsidePie = (x, y) => {
if (!ref.current) return false;
const { left: pieX, top: pieY } = ref.current.getBoundingClientRect();
const distance = (x - pieX - radiusPx) ** 2 + (y - pieY - radiusPx) ** 2;
const distance = (x - (pieX - window.pageXOffset) - radiusPx) ** 2
+ (y - (pieY + window.pageYOffset) - radiusPx) ** 2;
return centerArea <= distance && distance <= pieArea;
};

Expand All @@ -82,8 +83,10 @@ const PieMenu = ({
React.useEffect(() => {
const captureActiveSlice = rafSchedule(e => {
if (!ref.current) return;
const x = e.pageX !== undefined ? e.pageX : (e: TouchEvent).touches[0].clientX;
const y = e.pageY !== undefined ? e.pageY : (e: TouchEvent).touches[0].clientY;
const x = (e.pageX !== undefined ? e.pageX : (e: TouchEvent).touches[0].clientX)
- window.pageXOffset;
const y = (e.pageY !== undefined ? e.pageY : (e: TouchEvent).touches[0].clientY)
- window.pageYOffset;
if (x > -1 && y > -1) {
const item = getItemAt(x, y);
if (item && item.id) {
Expand Down

0 comments on commit 5809034

Please sign in to comment.