Skip to content

Instantly share code, notes, and snippets.

@subchen
Last active August 29, 2015 14:08
Show Gist options
  • Save subchen/948db860c2a425878ffa to your computer and use it in GitHub Desktop.
Save subchen/948db860c2a425878ffa to your computer and use it in GitHub Desktop.
获取整个document最大可用的 zIndex
(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