Created
May 14, 2018 08:51
-
-
Save adamo/59f2f3463c54c9ad3e656195fa447ec1 to your computer and use it in GitHub Desktop.
Coffee script version of vanilla js sticky header
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
| 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