Created
September 16, 2022 21:03
-
-
Save israelss/5575266e32be867d04657b271f73c863 to your computer and use it in GitHub Desktop.
Find and return scrolled parent of a HTML element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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