Created
December 13, 2016 19:58
-
-
Save YohannParis/5968f0537fd01cb1f855eb7115da9e44 to your computer and use it in GitHub Desktop.
Easy and quick way to add a sticky element.
This file contains 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
var header = document.querySelector('.header'); | |
var origOffsetY = header.offsetTop; | |
function onScroll(e) { | |
window.scrollY >= origOffsetY ? header.classList.add('sticky') : | |
header.classList.remove('sticky'); | |
} | |
document.addEventListener('scroll', onScroll); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment