Skip to content

Instantly share code, notes, and snippets.

@pakMann
Last active October 13, 2015 15:38
Show Gist options
  • Select an option

  • Save pakMann/4217983 to your computer and use it in GitHub Desktop.

Select an option

Save pakMann/4217983 to your computer and use it in GitHub Desktop.
sticky menu on header
$topContent = $("#homepage")
$nav = $(".navbar")
navHeight = $nav.outerHeight(false)
stickyNav = ->
browserHeight = $(window).height()
navTopPos = browserHeight - navHeight
$topContent.css height: navTopPos
scrollTop = $(window).scrollTop()
if scrollTop > navTopPos
$nav.css
position: "fixed"
top: 0
width: "100%"
else
$nav.removeAttr "style"
stickyNav()
$(window).resize ->
stickyNav()
$(window).scroll ->
stickyNav()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment