Skip to content

Instantly share code, notes, and snippets.

@adamo
Created May 14, 2018 08:51
Show Gist options
  • Save adamo/59f2f3463c54c9ad3e656195fa447ec1 to your computer and use it in GitHub Desktop.
Save adamo/59f2f3463c54c9ad3e656195fa447ec1 to your computer and use it in GitHub Desktop.
Coffee script version of vanilla js sticky header
sticky =
sticky_after: 200
init: ->
@header = document.getElementsByTagName('header')[0]
@clone = @header.cloneNode(true)
@clone.classList.add 'clone'
# @header.insertBefore @clone
@scroll()
@events()
return
scroll: ->
if window.scrollY > @sticky_after
document.body.classList.add 'scrolled'
else
document.body.classList.remove 'scrolled'
return
events: ->
window.addEventListener 'scroll', @scroll.bind(this)
return
document.addEventListener 'DOMContentLoaded', sticky.init.bind(sticky)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment