Created
April 9, 2021 17:22
-
-
Save cviebrock/4e6be47816a34534f43ede3b13ecb53a to your computer and use it in GitHub Desktop.
Get max z-index of all elements on a page
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
const reducer = (max, elem) => { | |
const s = window.getComputedStyle(elem); | |
const z = parseInt(s.getPropertyValue('z-index'), 10) || 0; | |
return Math.max(max, z); | |
}; | |
const maxZ = Array.from(document.getElementsByTagName('*')) | |
.reduce(reducer, Number.MIN_SAFE_INTEGER); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment