Last active
January 2, 2024 22:14
-
-
Save pedro-mass/50c31c5bb6e874458791108de13ad5ab to your computer and use it in GitHub Desktop.
CSS Helpers
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
// Replace “.the-fixed-child” for a CSS selector | |
// that matches the fixed-position element: | |
const selector = ".fixed"; | |
function findCulprits(elem) { | |
if (!elem) { | |
throw new Error(`Could not find element with selector: "${selector}"`); | |
} | |
let parent = elem.parentElement; | |
while (parent) { | |
const { transform, willChange, filter } = getComputedStyle(parent); | |
if ( | |
transform !== "none" || | |
willChange === "transform" || | |
filter !== "none" | |
) { | |
console.warn("🚨 Found a culprit! 🚨\n", parent, { | |
transform, | |
willChange, | |
filter, | |
}); | |
} | |
parent = parent.parentElement; | |
} | |
} | |
findCulprits(document.querySelector(selector)); |
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
// ref: https://courses.joshwcomeau.com/css-for-js/02-rendering-logic-2/17-troubleshooting | |
// 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