Skip to content

Instantly share code, notes, and snippets.

@LaboratorioEfe5
Created January 21, 2016 11:51
Show Gist options
  • Save LaboratorioEfe5/922347b862db71be8524 to your computer and use it in GitHub Desktop.
Save LaboratorioEfe5/922347b862db71be8524 to your computer and use it in GitHub Desktop.
sticky header pure javascript/css (no jquery)
/*paste this code in the footer*/
<script>
window.onscroll = function() {
var el = document.getElementById('headerWrapper'); // rename with your header wrapper id
if(window.pageYOffset > 1) {
//sticky header
el.classList.add("sticky");
} else {
//normal header
el.classList.remove("sticky");
}
}</script>
/*Replace with your header wrapper #headerWrapper */
#headerWrapper {
transition: all 0.4s ease;
}
#headerWrapper.sticky {
position: fixed;
width: 100%;
top: 0;
left: 0;
padding-top: 10px;
background: #fff;
}
/* replace with your logo class or improve efect*/
.sticky #logo {
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment