Skip to content

Instantly share code, notes, and snippets.

@adamo
Created December 22, 2015 12:05
Show Gist options
  • Select an option

  • Save adamo/39d9c0259e96ace8b7a1 to your computer and use it in GitHub Desktop.

Select an option

Save adamo/39d9c0259e96ace8b7a1 to your computer and use it in GitHub Desktop.
add animated class to header on scroll vanilla js
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