Skip to content

Instantly share code, notes, and snippets.

@bultas
Created May 13, 2020 14:57
Show Gist options
  • Save bultas/fed1a80c4cce37c3a23e0c02afcc6dea to your computer and use it in GitHub Desktop.
Save bultas/fed1a80c4cce37c3a23e0c02afcc6dea to your computer and use it in GitHub Desktop.
Get max zIndex in NodeList (document)
function convertToNumber(value) {
const asNumber = parseFloat(value);
return Number.isNaN(asNumber) ? 0 : asNumber;
}
function getNodeZIndex(node) {
const computedIndex = convertToNumber(window.getComputedStyle(node).zIndex);
const styleIndex = convertToNumber(node.style.zIndex);
if (computedIndex > styleIndex) {
return computedIndex;
}
return styleIndex;
}
export function maxZIndex(nodeList) {
const zIndexes = Array.from(nodeList).map(getNodeZIndex);
return Math.max(...zIndexes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment