type ElementOrWindow = HTMLElement | Window ; param { Element } element param { Element } rootParent returns { Element | window } export function getScrollEventTarget ( element , rootParent = window ) { let node = element ; while ( node && node . tagName !== 'HTML' && node . tagName !== 'BODY' && node . nodeType === 1 && node !== rootParent ) { const { overflowY } = window . getComputedStyle ( node ) ; if ( overflowY === 'scroll' || overflowY === 'auto' ) { return node ; } node = < HTMLElement > node . parentNode ; } return rootParent ; } export function getScrollTop ( element ) { return 'scrollTop' in element ? element . scrollTop : element . pageYOffset ; } export function setScrollTop ( element , value ) { 'scrollTop' in element ? ( element . scrollTop = value ) : element . scrollTo ( element . scrollX , value ) ; } export function getElementTop ( element ) { return ( ( element === window ? 0 : ( element as HTMLElement ) . getBoundingClientRect ( ) . top ) + getScrollTop ( window ) ) ; } export function getVisibleHeight ( element ) { return element === window ? element . innerHeight : ( element as HTMLElement ) . getBoundingClientRect ( ) . height ; }