Skip to content

Instantly share code, notes, and snippets.

@JeffreyATW
Created January 29, 2016 01:15
Show Gist options
  • Save JeffreyATW/4fb7b08837460549350a to your computer and use it in GitHub Desktop.
Save JeffreyATW/4fb7b08837460549350a to your computer and use it in GitHub Desktop.
Get the maximum z-index of an element's ancestors
var getMaxZIndex = function (element, maxZIndex) {
var maxZIndex = maxZIndex || 0;
var zIndex = element.css('z-index');
if (zIndex !== 'auto') {
maxZIndex = Math.max(maxZIndex, zIndex);
}
var parent = element.parent();
if (parent[0].nodeName === 'HTML') {
return maxZIndex;
} else {
return getMaxZIndex(parent, maxZIndex);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment