Last active
August 15, 2018 12:11
-
-
Save davidhund/105050d8d416b7b24d33713504a9edff to your computer and use it in GitHub Desktop.
Log the highest used z-index
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
/** | |
* Log highest z-index used on page | |
* @author: davidhund / @valuedstandards | |
* | |
* Do not use this in (production) JS code! | |
* To be used as e.g. a Chrome Devtools snippet, bookmarklet etc.. | |
*/ | |
(function(w,d,z) { | |
console.log(`Highest z-index in use is: %d`, | |
Math.max(... | |
[...d.querySelectorAll('*')] | |
// Only include elements with valid z-index values | |
//.filter(e => !!~~w.getComputedStyle(e,null).getPropertyValue(z)) | |
// Commented above: | |
// Filtering is actually not quite necessary since we cast to a number | |
// ..so 'invalid' values return '0'... | |
.map(e => ~~w.getComputedStyle(e,null).getPropertyValue(z)) | |
) | |
); | |
})(window, document, 'z-index'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
window.getComputedStyle(el).getPropertyValue(prop)
can probably soon be replaced with the new typedel.computedStyleMap().get(prop)
:https://developers.google.com/web/updates/2018/03/cssom