Last active
November 24, 2023 10:36
-
-
Save nikolailehbrink/47839304b8b5f1ea985c3ebd7ad75467 to your computer and use it in GitHub Desktop.
Scroll based navigation bar shadow
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
window.onscroll = function () { | |
scrollTop(); | |
}; | |
function scrollTop() { | |
if (document.body.scrollTop > 0 || document.documentElement.scrollTop > 0) { | |
document.getElementById("navbar").classList.add("shadow-md"); | |
} else { | |
document.getElementById("navbar").classList.remove("shadow-md"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be good to implement a throttling function with for example _.throttle().