Created
July 22, 2019 18:11
-
-
Save oliverll1/0943a8abccf52b9407e56960acfdf403 to your computer and use it in GitHub Desktop.
Change header background on scroll
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
function runOnScroll() { | |
const header = document.getElementById("header"); | |
const bodyScroll = document.getElementsByTagName("body")[0].scrollTop; | |
// Chrome | |
const htmlScroll = document.getElementsByTagName("html")[0].scrollTop; | |
if ( bodyScroll >= 400 || htmlScroll >= 400) { | |
header.style.background = "#615e5d"; | |
} | |
else{ | |
header.style.background = "none"; | |
} | |
}; | |
window.addEventListener("scroll", runOnScroll); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment