mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
Merge pull request #561 from saleebm/compat/back-to-top
add scroll to top compatibility with other browsers
This commit is contained in:
commit
80c7a41d21
1 changed files with 9 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue