Created
March 7, 2017 04:19
-
-
Save nt1m/06910eae5ebe45865b18ce56a2b3aebc to your computer and use it in GitHub Desktop.
This file contains 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
function getPositionReference(node) { | |
let pos = getComputedStyle(node).getPropertyValue("position"); | |
switch (pos) { | |
case "relative": | |
return node; | |
case "absolute": | |
let parentPosition = "static"; | |
let parent = node.parentNode; | |
while (parentPosition == "static" && parent.parentNode) { | |
parent = parent.parentNode; | |
} | |
return parent; | |
case "fixed": | |
return window; // corresponds to the viewport, not to any element... | |
case "sticky": | |
// this acts like position: relative in some cases and position: fixed in others | |
// mainly depends on scroll position | |
// TODO. | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment