Skip to content

Instantly share code, notes, and snippets.

@israelss
Created September 16, 2022 21:03
Show Gist options
  • Save israelss/5575266e32be867d04657b271f73c863 to your computer and use it in GitHub Desktop.
Save israelss/5575266e32be867d04657b271f73c863 to your computer and use it in GitHub Desktop.
Find and return scrolled parent of a HTML element
export const getScrolledParent = (el: HTMLElement | null): HTMLElement | null => {
if (el === null || el.parentElement === null) return null
if (el.parentElement.scrollTop > 0) return el.parentElement
return getScrolledParent(el.parentElement)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment