Last active
December 31, 2015 02:29
-
-
Save jsatk/7921133 to your computer and use it in GitHub Desktop.
For when you really want your shit on top.
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
var fuckYouIWantMyShitOnTop = function (idOfElementYouWantOnTop) { | |
var all = document.getElementsByTagName("*"), | |
maxZIndex = 9007199254740992, // https://gist.github.com/jsatk/7921133#comment-968150 | |
i, highestZIndex, currentZIndex, currentEl; | |
for (i = all.length - 1; i >= 0; i--) { | |
currentEl = all[i]; | |
currentZIndex = Number(currentEl.style.zIndex); | |
if (isNaN(currentZIndex)) continue; | |
highestZIndex = isNaN(highestZIndex) || currentZIndex > highestZIndex ? currentZIndex : highestZIndex; | |
currentEl.style.zIndex = currentZIndex === maxZIndex ? currentZIndex - 1 : currentZIndex; | |
} | |
document.getElementById(idOfElementYouWantOnTop).style.zIndex = highestZIndex + 1; | |
}; |
You might want to lower the zindex of everything else that is at 9007199254740992.
@joelmccracken @msepcot Done :)
@chriscoyier that's brilliant and terrifying. This entire thing is terrifying and was created as a joke. The only real use case I can see for this is if you're on a giant project and some element keeps getting covered up by other non-careful coders who abuse z-index
you could invoke this script with the ID if the el you want on top somewhere ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another way maybe to do it would be to wrap the entire contents of the body in a
<div>
with position: relative; z-index: 1; and like overflow: auto; then insert your thing AFTER that div with also some positioning other than static and a z-index: 2; - That way everything else is stuck in that new context and your stuff is in a new, higher context. I think that should work.