Created
April 1, 2021 14:51
-
-
Save RyanHirsch/92acade4313d74fe32696575bb0faaad to your computer and use it in GitHub Desktop.
Traverse up the dom to find sticky parent
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
/** | |
* Traverse up the dom to find a sticky parent node crossing any shadow boundaries | |
*/ | |
export function findStickyParent(element: HTMLElement): HTMLElement | null { | |
let elm = element.parentNode || element.host; | |
while (elm) { | |
if (elm.style && elm.style.top && window.getComputedStyle(elm).position === `sticky`) { | |
return elm; | |
} | |
elm = elm.parentNode || elm.host; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment