Skip to content

Instantly share code, notes, and snippets.

@davidhund
Last active August 15, 2018 12:11
Show Gist options
  • Save davidhund/105050d8d416b7b24d33713504a9edff to your computer and use it in GitHub Desktop.
Save davidhund/105050d8d416b7b24d33713504a9edff to your computer and use it in GitHub Desktop.
Log the highest used z-index
/**
* 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');
@davidhund
Copy link
Author

window.getComputedStyle(el).getPropertyValue(prop) can probably soon be replaced with the new typed el.computedStyleMap().get(prop):
https://developers.google.com/web/updates/2018/03/cssom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment