Skip to content

Instantly share code, notes, and snippets.

@Rycochet
Created January 27, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rycochet/a797f78bc93fa274d32550ad99644101 to your computer and use it in GitHub Desktop.
Save Rycochet/a797f78bc93fa274d32550ad99644101 to your computer and use it in GitHub Desktop.
offsetParent polyfill
if (!("offsetParent" in document.body)) {
Object.defineProperty(HTMLElement.prototype, "offsetParent", {
"get": function() {
var element = this,
parent = element.parentElement,
html = document.documentElement,
found = null,
style = window.getComputedStyle(element);
if (element && style.position !== "fixed") {
for (; parent; parent = parent.parentElement) {
style = window.getComputedStyle(parent);
if (style.display === "none") {
found = null;
break;
} else if (!found && (parent === html || style.position !== "initial")) {
found = parent;
}
}
}
return found;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment