-
-
Save jsatk/7921133 to your computer and use it in GitHub Desktop.
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; | |
}; |
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.
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 ;)
OK now that's just rude.