Last active
August 29, 2015 14:08
-
-
Save subchen/948db860c2a425878ffa to your computer and use it in GitHub Desktop.
获取整个document最大可用的 zIndex
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(window, jetbrick) { | |
/** | |
* 获取整个document最大可用的 zIndex | |
* | |
* @returns {Number} | |
*/ | |
jetbrick.zIndex = function() { | |
var nodes = window.document.getElementsByTagName("*"); | |
var max = 0; | |
for (var i = 0; i < nodes.length; i++) { | |
var node = nodes[i]; | |
var zIndex; | |
if (window.getComputedStyle) { | |
var styles = window.getComputedStyle(node, null); | |
zIndex = styles.getPropertyValue("zIndex") || styles.zIndex; | |
} else if (node.currentStyle) { | |
zIndex = node.currentStyle.zIndex; | |
} else { | |
zIndex = node.style.zIndex; | |
} | |
if (zIndex !== "") { | |
zIndex = (+zIndex) || 0; | |
if (max < zIndex) { | |
max = zIndex; | |
} | |
} | |
} | |
return max + 1; | |
}; | |
})(window, window.jetbrick || (window.jetbrick = {})); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment