Created
March 17, 2022 21:13
-
-
Save jbd91/27c3002289f58c0203ace67c3bd2113c to your computer and use it in GitHub Desktop.
Sticky
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
// Sticky Navigation | |
var header = document.getElementById('header'); | |
var sticky = header.offsetTop; | |
window.onscroll = function () { | |
stickyNav() | |
}; | |
function stickyNav() { | |
if (window.pageYOffset > sticky) { | |
header.classList.add('sticky'); | |
} else { | |
header.classList.remove('sticky'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment