Skip to content

Instantly share code, notes, and snippets.

@vlazzle
Created October 16, 2009 01:00
Show Gist options
  • Save vlazzle/211453 to your computer and use it in GitHub Desktop.
Save vlazzle/211453 to your computer and use it in GitHub Desktop.
/*
* usage example:
* $('body').zIndices()
*
* Returns a hash with z-indices as keys whose corresponding
* values are elements with that z-index set. Any z-index <z>
* having more than one element will also be in the hash
* under the key '!<z>' (to be sorted together near the top),
* as well as the regular key, '<z>'.
*/
jQuery.fn.zIndices = function() {
var indices = {};
this.each(function() {
var fn = arguments.callee;
$(this).contents().each(function() {
var z = NaN;
if (this.style) {
z = parseInt(this.style.zIndex);
}
if (!isNaN(z)) {
if (typeof indices[z] === 'undefined') {
indices[z] = [this];
} else {
indices[z].push(this);
}
}
fn.apply($(this));
});
});
return indices;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment