Skip to content

Instantly share code, notes, and snippets.

@nikolailehbrink
Last active November 24, 2023 10:36
Show Gist options
  • Save nikolailehbrink/47839304b8b5f1ea985c3ebd7ad75467 to your computer and use it in GitHub Desktop.
Save nikolailehbrink/47839304b8b5f1ea985c3ebd7ad75467 to your computer and use it in GitHub Desktop.
Scroll based navigation bar shadow
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");
}
}
@nikolailehbrink
Copy link
Author

Would be good to implement a throttling function with for example _.throttle().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment