diff --git a/src/components/BackToTop.js b/src/components/BackToTop.js index faaab8a1..a329ff37 100644 --- a/src/components/BackToTop.js +++ b/src/components/BackToTop.js @@ -24,6 +24,14 @@ const BackToTopLink = styled.a` } `; +function scrollTopMax() { + let ref; + // scrollTopMax is only on Firefox right now! https://caniuse.com/#search=scrolltopmax + return (ref = document.scrollingElement.scrollTopMax) != null + ? ref + : document.scrollingElement.scrollHeight - document.documentElement.clientHeight +} + function useScrollPosition() { const [percent, setPercent] = useState(0); @@ -31,7 +39,7 @@ function useScrollPosition() { console.log(document.documentElement.scrollTop); const howFar = document.documentElement.scrollTop / - document.documentElement.scrollTopMax; + scrollTopMax(); setPercent(howFar); }