Skip to content

Instantly share code, notes, and snippets.

@nuriye
Created December 3, 2018 12:38
Show Gist options
  • Save nuriye/1f56e79c229bd040b6b11bd8f6ce5a75 to your computer and use it in GitHub Desktop.
Save nuriye/1f56e79c229bd040b6b11bd8f6ce5a75 to your computer and use it in GitHub Desktop.
Sticky Header/Navi
<script>
jQuery( document ).ready(function($) {
window.onscroll = function() {
getSticky();
};
var header = document.getElementById("wrapper-navbar");
var sticky = header.offsetTop;
function getSticky() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
$('#navbarNavDropdown').removeClass('show');
} else {
header.classList.remove("sticky");
}
}
});
</script>
<style>
.sticky {
position: fixed;
top: 0;
width: 100%;
z-index: 999;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment