Skip to content

Instantly share code, notes, and snippets.

@quannt
Created June 25, 2021 15:04
Show Gist options
  • Save quannt/a6a8a38a5605722db2bbfae0581a0320 to your computer and use it in GitHub Desktop.
Save quannt/a6a8a38a5605722db2bbfae0581a0320 to your computer and use it in GitHub Desktop.
// 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 {
transform,
willChange
} = getComputedStyle(parent);
if (transform !== 'none' || willChange === 'transform') {
console.warn(
'🚨 Found a culprit! 🚨\n',
parent,
{ transform, willChange }
);
}
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