Skip to content

Instantly share code, notes, and snippets.

@vishnun
Created October 30, 2013 05:16
Show Gist options
  • Save vishnun/7227551 to your computer and use it in GitHub Desktop.
Save vishnun/7227551 to your computer and use it in GitHub Desktop.
My Gist to make a stick to top kinda header
$(document).ready ->
StickTop.initApp()
@StickTop =
app:
initHeaderBinding: (headerSelector)->
$(window).on "scroll", ()->
if $('body').scrollTop() > 65
$(headerSelector).addClass('fixed-to-top')
$('.stick-top').slideDown(400)
$('body').css({'margin-top': '60px'})
else
$(headerSelector).removeClass('fixed-to-top').removeAttr('style')
$('body').css({'margin-top': '0px'})
initApp: ()->
@app.initHeaderBinding('#header')
#header{
margin: 0 auto;
background: #ccc;
&.stick-top {
min-height: 61px;
}
&.fixed-to-top { // Added using Javascript
position: fixed;
top: 0;
left: 0;
display: none;
z-index: 1200;
right: 0;
box-shadow: 1px 3px 10px #888;
opacity: 0.98;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment