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.
511 B · 19 lines
TypeScript
at main
1234567891011121314151617181920import useScrollLeft from './useScrollLeft.js';import useWindowWidth from './useWindowWidth.js';
export default function useScrollLeftPercent(): number | null { const scrollLeft = useScrollLeft(); const windowWidth = useWindowWidth();
if (scrollLeft === null || windowWidth === null) { return null; }
const { scrollWidth } = document.documentElement;
if (scrollWidth === 0 || scrollWidth === windowWidth) { return 0; }
return scrollLeft / Math.max(0, scrollWidth - windowWidth);}