From cc19d272d3d3d950286fcfb0d1e25d01fc12c3f3 Mon Sep 17 00:00:00 2001 From: psychobolt <560721+psychobolt@users.noreply.github.com> Date: Sat, 11 Sep 2021 17:24:03 -0700 Subject: [PATCH] Add page offset to pointer position #22 --- src/PieMenu.component.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PieMenu.component.js b/src/PieMenu.component.js index ddb580b8..043ee289 100644 --- a/src/PieMenu.component.js +++ b/src/PieMenu.component.js @@ -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; };