Created
January 21, 2016 11:51
-
-
Save LaboratorioEfe5/922347b862db71be8524 to your computer and use it in GitHub Desktop.
sticky header pure javascript/css (no jquery)
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
/*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> |
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
/*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