Last active
December 4, 2017 10:57
-
-
Save thebirk/d87d97f8a8955573bafc508b1fa823af to your computer and use it in GitHub Desktop.
Pls never forget
This file contains hidden or 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
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