Skip to content

Instantly share code, notes, and snippets.

@thebirk
Last active December 4, 2017 10:57
Show Gist options
  • Save thebirk/d87d97f8a8955573bafc508b1fa823af to your computer and use it in GitHub Desktop.
Save thebirk/d87d97f8a8955573bafc508b1fa823af to your computer and use it in GitHub Desktop.
Pls never forget
window.addEventListener("scroll", function() {
var spoiler = document.getElementById("spoiler2");
var div = document.getElementsByClassName("problem")[0];
var divs = document.querySelectorAll(".divspoiler");
var spoilers = document.querySelectorAll("input[id^=\"spoiler\"]");
//console.log(labels);
var divsfratop = [];
divs.forEach(function(item, index) {
divsfratop.push(item.getBoundingClientRect().y | 0);
});
var found_spoiler = false;
for(var i = divsfratop.length-1; i >= 0; i--) {
if(!found_spoiler && divsfratop[i] < 0) {
spoilers[i].classList.add("stick");
spoilers[i].setAttribute("style", "z-index: 1;");
found_spoiler = true;
} else {
spoilers[i].classList.remove("stick");
spoilers[i].setAttribute("style", "z-index: 0;");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment