Created
January 27, 2017 11:41
-
-
Save Rycochet/a797f78bc93fa274d32550ad99644101 to your computer and use it in GitHub Desktop.
offsetParent polyfill
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
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