Last active
May 14, 2024 03:14
-
-
Save linj121/75f313248bcd02c13a1ae21e3db745a5 to your computer and use it in GitHub Desktop.
This file contains 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
// Author: Josh Comeau | |
// https://courses.joshwcomeau.com/css-for-js | |
// Replace “.the-sticky-child” for a CSS selector | |
// that matches the sticky-position element: | |
const selector = '.the-sticky-child'; | |
function findCulprits(elem) { | |
if (!elem) { | |
throw new Error( | |
'Could not find element with that selector' | |
); | |
} | |
let parent = elem.parentElement; | |
while (parent) { | |
const { overflow } = getComputedStyle(parent); | |
if (['auto', 'scroll', 'hidden'].includes(overflow)) { | |
console.log(overflow, parent); | |
} | |
parent = parent.parentElement; | |
} | |
} | |
findCulprits(document.querySelector(selector)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment