Skip to content

Instantly share code, notes, and snippets.

@linj121
Last active May 14, 2024 03:14
Show Gist options
  • Save linj121/75f313248bcd02c13a1ae21e3db745a5 to your computer and use it in GitHub Desktop.
Save linj121/75f313248bcd02c13a1ae21e3db745a5 to your computer and use it in GitHub Desktop.
// 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