mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
simplify scrollTop
This commit is contained in:
parent
80c7a41d21
commit
4c0cb690d3
1 changed files with 4 additions and 12 deletions
|
|
@ -24,22 +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() {
|
function useScrollPosition() {
|
||||||
const [percent, setPercent] = useState(0);
|
const [percent, setPercent] = useState(0);
|
||||||
|
|
||||||
function handleScroll(event) {
|
function handleScroll(event) {
|
||||||
console.log(document.documentElement.scrollTop);
|
const scrollTop =
|
||||||
const howFar =
|
document.scrollingElement.scrollHeight -
|
||||||
document.documentElement.scrollTop /
|
document.documentElement.clientHeight;
|
||||||
scrollTopMax();
|
const howFar = document.documentElement.scrollTop / scrollTop;
|
||||||
setPercent(howFar);
|
setPercent(howFar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue