Created
December 22, 2015 12:05
-
-
Save adamo/39d9c0259e96ace8b7a1 to your computer and use it in GitHub Desktop.
add animated class to header on scroll vanilla js
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
| masthead = document.getElementById("masthead") | |
| height = 100 | |
| stop = height | |
| window.onscroll = (e) -> | |
| scrollTop = (if (window.pageYOffset isnt `undefined`) then window.pageYOffset else (document.documentElement or document.body.parentNode or document.body).scrollTop) | |
| # console.log scrollTop | |
| # masthead.offsetTop; | |
| if scrollTop >= stop | |
| masthead.className = "site-header animated" | |
| else | |
| masthead.className = "site-header" | |
| return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment