Skip to content

Instantly share code, notes, and snippets.

@gchartier
Created October 13, 2021 18:22
Show Gist options
  • Save gchartier/07d88e911f335aff795cca313258c10e to your computer and use it in GitHub Desktop.
Save gchartier/07d88e911f335aff795cca313258c10e to your computer and use it in GitHub Desktop.
Sticky Element Parent Overflow Finder
// Replace this with a relevant selector.
// If you use a tool that auto-generates classes,
// you can temporarily add an ID and select it
// with '#id'.
const selector = '.the-fixed-child';
function findCulprits(elem) {
if (!elem) {
throw new Error(
'Could not find element with that selector'
);
}
let parent = elem.parentElement;
while (parent) {
const hasOverflow = getComputedStyle(parent).overflow;
if (hasOverflow !== 'visible') {
console.log(hasOverflow, parent);
}
parent = parent.parentElement;
}
}
findCulprits(document.querySelector(selector));
@gchartier
Copy link
Author

You can copy/paste this snippet into the browser console, replacing selector with a CSS selector that matches your sticky element. It will crawl up the DOM tree looking for an ancestor with overflow set to something other than visible (the default value).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment