Created
January 29, 2016 01:15
-
-
Save JeffreyATW/4fb7b08837460549350a to your computer and use it in GitHub Desktop.
Get the maximum z-index of an element's ancestors
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
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