Skip to content

Instantly share code, notes, and snippets.

@miketaylr
Forked from paulirish/zIndex-bookmarklet.js
Created October 15, 2009 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketaylr/211213 to your computer and use it in GitHub Desktop.
Save miketaylr/211213 to your computer and use it in GitHub Desktop.
// find all elements with a z-index and indicate what they are.
function contrast(color){ return '#' +
(Number('0x'+color.substr(1)).toString(10) > 0xffffff/2 ? '000000' : 'ffffff');
}
jQuery('*')
.filter(function(){ return $(this).css('zIndex') !== 'auto'; })
.each(function(){
var color = '#'+Math.floor(Math.random()*16777215).toString(16); // <3 temp01
if ($(this).css('position').match(/absolute|relative/)) $(this).css('position','relative');
$(this).css('border','1px solid '+color);
$('<span>z-index: '+ $(this).css('zIndex') + '</span>')
.css({'background':color, color: contrast(color), position:'absolute', top:0,left:0,textIndent:0})
.appendTo(this);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment