Created
October 30, 2013 05:16
-
-
Save vishnun/7227551 to your computer and use it in GitHub Desktop.
My Gist to make a stick to top kinda header
This file contains 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
$(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') |
This file contains 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
#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