Created
October 16, 2009 01:00
-
-
Save vlazzle/211453 to your computer and use it in GitHub Desktop.
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
/* | |
* 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