UNPKG

@wojtekmaj/react-hooks

Version:

A collection of React Hooks.

15 lines (14 loc) 486 B
import useScrollTop from './useScrollTop.js'; import useWindowHeight from './useWindowHeight.js'; export default function useScrollTopPercent() { const scrollTop = useScrollTop(); const windowHeight = useWindowHeight(); if (scrollTop === null || windowHeight === null) { return null; } const { scrollHeight } = document.documentElement; if (scrollHeight === 0) { return 0; } return scrollTop / Math.max(0, scrollHeight - windowHeight); }