Created
May 13, 2020 14:57
-
-
Save bultas/fed1a80c4cce37c3a23e0c02afcc6dea to your computer and use it in GitHub Desktop.
Get max zIndex in NodeList (document)
This file contains hidden or 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 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