onScroll Header animation
Last active
May 16, 2017 00:59
-
-
Save hew/8a3d4cc6ab13bc5ea3ecb4df8f4f2fef to your computer and use it in GitHub Desktop.
onScroll Header animation
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
// Header Styles | |
var stuck = false; | |
var stickPoint = getDistance(); | |
function getDistance() { | |
var topDist = topNav.offsetTop; | |
return topDist; | |
} | |
window.onscroll = function(e) { | |
var distance = getDistance() - window.pageYOffset; | |
var offset = window.pageYOffset; | |
if ( (distance <= 0) && !stuck) { | |
topNav.classList.add('top'); | |
stuck = true; | |
} else if (stuck && (offset <= stickPoint)){ | |
topNav.classList.remove('top'); | |
stuck = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment