Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | const getTarget = value => { Iif (value instanceof HTMLElement) { return value } else Eif (value === window.document) { return value.body } else if (value instanceof Object) { return value.current } else { return value } } export const isDocumentElement = target => target === window.document const calcBackToTopEngine = (target = window.document, minHeight) => { const element = getTarget(target) const isDocument = isDocumentElement(target) const scrollTop = isDocument ? window.scrollY : element.scrollTop const clientHeight = isDocument ? window.innerHeight - (element.offsetHeight - element.clientHeight) : element.clientHeight const offsetHeight = isDocument ? window.innerHeight : element.offsetHeight const scrollHeight = isDocument ? element.scrollHeight : element.scrollHeight const borderHeight = offsetHeight - clientHeight const properties = { scrollTop, clientHeight, offsetHeight, scrollHeight, borderHeight, minHeight } return [ // if the scrolled area exceeds a quarter of its scrollable visible area, it might return true by default scrollTop > (minHeight !== undefined ? minHeight : clientHeight / 4), properties ] } export default calcBackToTopEngine |