Skip to content

Instantly share code, notes, and snippets.

@andysolomon
Forked from blackfalcon/sticky-scroll.css
Created October 27, 2013 20:51
Show Gist options
  • Select an option

  • Save andysolomon/7187727 to your computer and use it in GitHub Desktop.

Select an option

Save andysolomon/7187727 to your computer and use it in GitHub Desktop.
.fixed {
position: fixed;
top: 0;
}
<div data-behavior="stick-to-top">
content ....
</div>
$ ->
el = $('[data-behavior~=stick-to-top]')
return if el.length == 0
top = false
$(window).scroll ->
top ||= el.offset().top - parseInt(el.css('marginTop'))
windowTop = $(window).scrollTop()
el.toggleClass('fixed', windowTop >= top)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment