Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/react-hooks. A collection of React Hooks.
hooks react react-hooks
Something went wrong. Try again.
515 B · 19 lines
TypeScript
at main
1234567891011121314151617181920import useScrollTop from './useScrollTop.js';import useWindowHeight from './useWindowHeight.js';
export default function useScrollTopPercent(): number | null { const scrollTop = useScrollTop(); const windowHeight = useWindowHeight();
if (scrollTop === null || windowHeight === null) { return null; }
const { scrollHeight } = document.documentElement;
if (scrollHeight === 0 || scrollHeight === windowHeight) { return 0; }
return scrollTop / Math.max(0, scrollHeight - windowHeight);}