From 5987cc82cc2f537c684bbd648fc11da9a97487d3 Mon Sep 17 00:00:00 2001 From: jeemyeong Date: Mon, 22 Jul 2019 20:44:55 +0900 Subject: [PATCH] feat: useWindowScroll - for cross-browser compatibility For cross-browser compatibility, use window.pageYOffset instead of window.scrollY. (https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY) --- src/useWindowScroll.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/useWindowScroll.ts b/src/useWindowScroll.ts index 33a86c98fc..218392adc1 100644 --- a/src/useWindowScroll.ts +++ b/src/useWindowScroll.ts @@ -9,8 +9,8 @@ export interface State { const useWindowScroll = (): State => { const frame = useRef(0); const [state, setState] = useState({ - x: isClient ? window.scrollX : 0, - y: isClient ? window.scrollY : 0, + x: isClient ? window.pageXOffset : 0, + y: isClient ? window.pageYOffset : 0, }); useEffect(() => { @@ -18,8 +18,8 @@ const useWindowScroll = (): State => { cancelAnimationFrame(frame.current); frame.current = requestAnimationFrame(() => { setState({ - x: window.scrollX, - y: window.scrollY, + x: window.pageXOffset, + y: window.pageYOffset, }); }); };